public eventSettings: EventSettingsModel = {
dataSource: this.data,
fields: {
subject: { name: 'Subject', validation: { required: true } },
location: {
name: 'Location', validation: {
required: true,
regex: ['^[a-zA-Z0-9- ]*$', 'Special character(s) not allowed in this field']
}
},
description: {
name: 'Description', validation: {
required: true, minLength: 5, maxLength: 500
}
},
startTime: { name: 'StartTime', validation: { required: true } },
endTime: { name: 'EndTime', validation: { required: true } }
}
}; |
Hi Akash,
Greetings from Syncfusion Support..!
We have validated your shared query at our end and suspect that your requirement is to add validations to the editor fields of the Scheduler and for that, we have prepared a sample using built-in validation options od scheduler which can be viewed from the following link.
UG link: https://ej2.syncfusion.com/angular/documentation/schedule/editor-template/#field-validation
public eventSettings: EventSettingsModel = {dataSource: this.data,fields: {subject: { name: 'Subject', validation: { required: true } },location: {name: 'Location', validation: {required: true,regex: ['^[a-zA-Z0-9- ]*$', 'Special character(s) not allowed in this field']}},description: {name: 'Description', validation: {required: true, minLength: 5, maxLength: 500}},startTime: { name: 'StartTime', validation: { required: true } },endTime: { name: 'EndTime', validation: { required: true } }}};
Kindly try the above solution and get back to us whether you need validation for custom fields on editor template or the above solution meets your requirement .
We will happy to assist you.
Regards,Hareesh
<ng-template #editorTemplate let-data>
<form
id="formId"
[formGroup]="reactForm"
#formDir="ngForm"
class="form-horizontal"
novalidate=""
>
<table
*ngIf="data != undefined"
class="custom-event-editor"
width="100%"
cellpadding="5"
>
<tbody>
<tr>
<td class="e-textlabel">Summary</td>
<td colspan="4">
<div class="e-float-input">
<input
id="Subject"
class="e-field e-input"
type="text"
value="{{data.Subject}}"
name="Subject"
style="width: 100%"
formControlName="check"
/>
<span class="e-float-line"></span>
</div>
<div *ngIf="check.errors">
<div
*ngIf="check.errors.required && check.touched"
class="e-error"
>
This field is required.
</div>
</div>
</td>
</tr>
<tr>
<td class="e-textlabel">Status</td>
<td colspan="4">
<ejs-dropdownlist
id="Status"
class="e-field"
data-name="Status"
placeholder="Choose Status"
[dataSource]="StatusData"
[fields]="statusFields"
value="{{data.Status}}"
>
</ejs-dropdownlist>
</td>
</tr>
<tr>
<td class="e-textlabel">From</td>
<td colspan="4">
<ejs-datetimepicker
id="StartTime"
class="e-field"
data-name="StartTime"
format="M/dd/yy h:mm a"
[value]="dateParser(data.startTime || data.StartTime)"
>
</ejs-datetimepicker>
</td>
</tr>
<tr>
<td class="e-textlabel">To</td>
<td colspan="4">
<ejs-datetimepicker
id="EndTime"
class="e-field"
data-name="EndTime"
format="M/dd/yy h:mm a"
[value]="dateParser(data.endTime || data.EndTime)"
>
</ejs-datetimepicker>
</td>
</tr>
<tr>
<td class="e-textlabel">Reason</td>
<td colspan="4">
<div class="e-float-input">
<textarea
id="Description"
class="e-field e-input"
name="Description"
rows="3"
cols="50"
value="{{data.Description}}"
style="width: 100%; height: 60px !important; resize: vertical"
formControlName="reason"
></textarea>
<span class="e-float-line"></span>
</div>
<div *ngIf="reason.errors">
<div
*ngIf="reason.errors.required && reason.touched"
class="e-error"
>
This field is required.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</form>
</ng-template> |
constructor() {
this.reactForm = new FormGroup({
check: new FormControl("", [FormValidators.required]),
reason: new FormControl("", [FormValidators.required])
});
}
get check() {
return this.reactForm.get("check");
}
get reason() {
return this.reactForm.get("reason");
} |
onBound(): void {
if (this.temp) {
this.http
.subscribe(data => {
let schObj = (document.querySelector(".e-schedule") as any)
.ej2_instances[0];
schObj.eventSettings.dataSource = data;
});
this.temp = false;
}
}
onBegin(args: any): void {
if (args.requestType === "eventCreate") {
this.http
headers: new HttpHeaders({
"Content-Type": "application/json"
})
})
.subscribe(data => {
let schObj = (document.querySelector(".e-schedule") as any)
.ej2_instances[0];
schObj.eventSettings.dataSource = data;
});
} else if (args.requestType === "eventChange") {
this.http
headers: new HttpHeaders({
"Content-Type": "application/json"
})
})
.subscribe(data => {
let schObj = (document.querySelector(".e-schedule") as any)
.ej2_instances[0];
schObj.eventSettings.dataSource = data;
});
} else if (args.requestType === "eventRemove") {
this.http
headers: new HttpHeaders({
"Content-Type": "application/json"
})
})
.subscribe(data => {
let schObj = (document.querySelector(".e-schedule") as any)
.ej2_instances[0];
schObj.eventSettings.dataSource = data;
});
}
} |