Dear Customer,
Greetings from Syncfusion support.
my problem is that validation doesn't work
We have validated your above query at our end. We have set the validation to the autocomplete component like the below code.
[app.component.html]
<ejs-autocomplete name="Country" id='Country' class="e-field" value='{{data.Location}}' [dataSource]='countriesData' [fields]='fields' (change)="onChange($event)"
data-name="Location">
<ng-template #itemTemplate let-data="">
<div class="list" (click)="selectLocation(data)">
<span><span class='name'> {{data.Country?.Name + ' - '}}</span><span class ='city'>{{data.Code?.Id}}</span></span>
</div>
</ng-template>
</ejs-autocomplete>
[app.component.ts]
const formElement: HTMLElement = args.element.querySelector('.e-schedule-form') as HTMLElement;
this.validator = (formElement as EJ2Instance).ej2_instances[0] as FormValidator;
this.validator.addRules('Country', { required: true });
I save my event, I don't get the value of my autocomplete field
We have validated your above query at our end. We have achieved it with the help of the below code.
[app.component.ts]
onPopupClose(args: PopupCloseEventArgs): void {
if (args.type === "Editor" && args.data) {
let location = ((args.element.querySelector("#Country") as EJ2Instance).ej2_instances[0] as AutoComplete).value;
(args.data as any).Location = location;
}
}
Kindly try the above sample and get back to us if you would require further assistance.
Regards,
Ravikumar Venkatesan