From 94e27c88bb968589bc8b9b5d6536ce6c0ba0b24f Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 12 Aug 2024 08:29:28 +0000 Subject: [PATCH] fix(@angular-devkit/schematics-cli): prevent bypassing select/checkbox prompts on validation failure Previously, when a select or checkbox prompt failed validation, it was bypassed, preventing users from correcting their input. This commit ensures that when validation fails, the prompts are re-displayed, allowing users to make the necessary corrections. This improves the user experience and helps avoid unintended selections. Closes #28189 (cherry picked from commit d4e95f2d153d4d604ea7555fcbb37710e56d86d7) --- packages/angular_devkit/schematics_cli/bin/schematics.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/angular_devkit/schematics_cli/bin/schematics.ts b/packages/angular_devkit/schematics_cli/bin/schematics.ts index d370edf98227..02272044c568 100644 --- a/packages/angular_devkit/schematics_cli/bin/schematics.ts +++ b/packages/angular_devkit/schematics_cli/bin/schematics.ts @@ -96,6 +96,13 @@ function _createPromptProvider(): schema.PromptProvider { )({ message: definition.message, default: definition.default, + validate: (values) => { + if (!definition.validator) { + return true; + } + + return definition.validator(Object.values(values).map(({ value }) => value)); + }, choices: definition.items.map((item) => typeof item == 'string' ? {