From c5ed0b1248dc2d5f895f4c4dc6737269a4854a1e Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 12 Aug 2024 08:28:30 +0000 Subject: [PATCH] fix(@angular/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 --- .../cli/src/command-builder/schematics-command-module.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/angular/cli/src/command-builder/schematics-command-module.ts b/packages/angular/cli/src/command-builder/schematics-command-module.ts index b1c88c6d8f3e..139f7d89059f 100644 --- a/packages/angular/cli/src/command-builder/schematics-command-module.ts +++ b/packages/angular/cli/src/command-builder/schematics-command-module.ts @@ -197,6 +197,13 @@ export abstract class SchematicsCommandModule definition.multiselect ? prompts.checkbox : prompts.select )({ message: definition.message, + validate: (values) => { + if (!definition.validator) { + return true; + } + + return definition.validator(Object.values(values).map(({ value }) => value)); + }, default: definition.default, choices: definition.items?.map((item) => typeof item == 'string'