BoldDesk®Customer service software with ticketing, live chat & omnichannel support, starting at $99/mo for unlimited agents. Try for free!
Chip list that I'm trying to get validation for and I'm not sure how to do it. I know that you would normally use a mat-error for a mat-chip-list but app-chips is called in a separate component called ChipsComponent.
html form where validation should occur
<form [formGroup]="addRemoveForm" novalidate>
<div class="col-md-12">
<app-chips
label="Entities"
placeholder="Add Entity..."
[options]="entityOptions"
[selectedOptions]="selectedEntities"
[hint]="
entityListHasDisabledOptions === true
? 'Please remove this contact from any roles for an entity prior to removing their association to that entity.'
: undefined
"
(onRemoved)="removeEntity($event)"
>
</app-chips>
</div>
</form>
ts for validation
export class DocumentDialog
addRemoveForm: FormGroup = new FormGroup(
{
......
selectedEntities: new FormControl('', [Validators.required]),
},
Separate component called ChipsComponent where app-chips is called as a selector
@Component({
selector: 'app-chips',
templateUrl: './chips.component.html',
})
export class ChipsComponent implements OnInit, DoCheck {
@Input() label = '';
@Input() placeholder = '';
@Input() options: Options[] = [];
@Input() selectedOptions: Options[] = [];
@Input() floatLabel: FloatLabelType = 'auto';
@Input() hint!: string | undefined;
chips.component.html
<mat-form-field [floatLabel]="floatLabel">
<mat-label>{{label}}</mat-label>
<mat-chip-list #optionList aria-label="label">
<mat-chip
*ngFor="let item of selectedOptions"
(removed)="onRemoved.emit(item)"
[removable]="!item.disabled"
[disabled]="item.disabled">
{{item.text}}
<mat-icon *ngIf="!item.disabled" matChipRemove>cancel</mat-icon>
</mat-chip>
<input
#optionInput
type="text"
[placeholder]="placeholder"
[formControl]="formControl"
[matAutocomplete]="optionAutoComplete"
[matChipInputFor]="optionList">
</mat-chip-list>
<mat-autocomplete
#optionAutoComplete="matAutocomplete"
(optionSelected)="selected($event.option.value)"
>
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{option.text}}
</mat-option>
</mat-autocomplete>
<mat-hint *ngIf="hint">{{ hint }}</mat-hint>
</mat-form-field>
<mat-form-field [floatLabel]="floatLabel">
<mat-label>{{label}}</mat-label>
<mat-chip-list #optionList aria-label="label">
<mat-chip
*ngFor="let item of selectedOptions"
(removed)="onRemoved.emit(item)"
[removable]="!item.disabled"
[disabled]="item.disabled">
{{item.text}}
<mat-icon *ngIf="!item.disabled" matChipRemove>cancel</mat-icon>
</mat-chip>
<input
#optionInput
type="text"
[placeholder]="placeholder"
[formControl]="formControl"
[matAutocomplete]="optionAutoComplete"
[matChipInputFor]="optionList">
</mat-chip-list>
<mat-autocomplete
#optionAutoComplete="matAutocomplete"
(optionSelected)="selected($event.option.value)"
>
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{option.text}}
</mat-option>
</mat-autocomplete>
<mat-hint *ngIf="hint">{{ hint }}</mat-hint>
</mat-form-field>
same question
i want to add validation into this
Hi Anjani,
Thank you for reaching out to Syncfusion support.
We appreciate your inquiry regarding validation with the mat-chip-list. Kindly explore the following blogs for general queries,
https://stackoverflow.com/questions/49959928/angular-material-mat-chip-validation
https://stackoverflow.com/questions/53483323/angular-2-material-mat-chip-list-formarray-validation
https://stackoverflow.com/questions/51690334/required-input-in-form-mat-chip-list-in-angular-2
If you have any questions or concerns regarding Syncfusion components, please don't hesitate to reach out to us.
Regards,
Jafar