Skip to content

doc-bug(cdk/listbox): remove forms validation and validation example #29391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/cdk/listbox/listbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,6 @@ The CDK Listbox supports both template driven forms and reactive forms.
"region": "listbox"
}) -->

#### Forms validation

The CDK listbox integrates with Angular's form validation API and has the following built-in
validation errors:

- `cdkListboxUnexpectedOptionValues` - Raised when the bound value contains values that do not
appear as option value in the listbox. The validation error contains a `values` property that
lists the invalid values
- `cdkListboxUnexpectedMultipleValues` - Raised when a single-selection listbox is bound to a value
containing multiple selected options.

<!-- example({
"example": "cdk-listbox-forms-validation",
"file": "cdk-listbox-forms-validation-example.ts",
"region": "errors"
}) -->

### Disabling options

You can disable options for selection by setting `cdkOptionDisabled`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@
}
<p>
Your zodiac sign is: <strong>{{signCtrl.value | json}}</strong>&nbsp;
<button (click)="signCtrl.setValue(['Cat'])">Set: Cat</button>&nbsp;
<button (click)="signCtrl.setValue(['Dragon', 'Snake'])">Set: Dragon, Snake</button>&nbsp;
<button (click)="signCtrl.setValue(['Cat', 'Rat'])">Set: Cat, Rat</button>&nbsp;
<button (click)="signCtrl.setValue([])">Clear</button>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ export class CdkListboxFormsValidationExample {
if (this.signCtrl.hasError('required')) {
errors.push('You must enter your zodiac sign');
}
if (this.signCtrl.hasError('cdkListboxUnexpectedMultipleValues')) {
errors.push('You can only select one zodiac sign');
}
if (this.signCtrl.hasError('cdkListboxUnexpectedOptionValues')) {
const invalidOptions = this.signCtrl.getError('cdkListboxUnexpectedOptionValues').values;
errors.push(`You entered an invalid zodiac sign: ${invalidOptions[0]}`);
}

return errors.length ? errors : null;
}
// #enddocregion errors
Expand Down
Loading