From 05a274a01365c21f69c0412f3455acd14cc6ddc5 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 (cherry picked from commit fae9542652d1e7cab6e785d13f8a0ac2400bed34) --- .../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'