Returns a set of violations
()
| 376 | |
| 377 | /** Returns a set of violations */ |
| 378 | validate(): string[] { |
| 379 | const violations: string[] = []; |
| 380 | |
| 381 | if (!this.inputs.multi() && this.inputs.value().length > 1) { |
| 382 | violations.push( |
| 383 | `A single-select tree should not have multiple selected options. Selected options: ${this.inputs.value().join(', ')}`, |
| 384 | ); |
| 385 | } |
| 386 | |
| 387 | const values = this.inputs.items().map(t => t.value()); |
| 388 | const duplicates = values.filter((val, idx) => values.indexOf(val) !== idx); |
| 389 | if (duplicates.length > 0) { |
| 390 | violations.push(`Duplicate tree item value '${duplicates[0]}' detected inside ngTree.`); |
| 391 | } |
| 392 | |
| 393 | return violations; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Sets the tree to it's default initial state. |