MCPcopy Create free account
hub / github.com/angular/components / validate

Method validate

src/aria/private/listbox/listbox.ts:210–232  ·  view source on GitHub ↗

Returns a set of violations

()

Source from the content-addressed store, hash-verified

208
209 /** Returns a set of violations */
210 validate(): string[] {
211 const violations: string[] = [];
212
213 if (!this.inputs.multi() && this.inputs.value().length > 1) {
214 violations.push(
215 `A single-select listbox should not have multiple selected options. Selected options: ${this.inputs.value().join(', ')}`,
216 );
217 }
218
219 const values = this.inputs.items().map(o => o.value());
220 const duplicates = values.filter((val, idx) => values.indexOf(val) !== idx);
221 if (duplicates.length > 0) {
222 violations.push(`Duplicate option value '${duplicates[0]}' detected inside ngListbox.`);
223 }
224
225 const ids = this.inputs.items().map(o => o.id());
226 const duplicateIds = ids.filter((id, idx) => ids.indexOf(id) !== idx);
227 if (duplicateIds.length > 0) {
228 violations.push(`Duplicate option ID '${duplicateIds[0]}' detected inside ngListbox.`);
229 }
230
231 return violations;
232 }
233
234 /** Handles keydown events for the listbox. */
235 onKeydown(event: KeyboardEvent) {

Callers

nothing calls this directly

Calls 4

pushMethod · 0.65
valueMethod · 0.45
filterMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected