Hi,
I am not getting solution to provide the validation on the Grid where I am using "#editTemplate" for editing. I have some columns out of which I need to put editing feature on only single column. And that single column would be dependent on the datatype.
Like if the programmatically provided data type is integer then there should be numeric textbox and if the datatype is Boolean then there has to be a checkbox etc. on that particular column. It means every row on the same column can have different type of datatype.
Everything is achieved so far. I am able to render the desired control as per the datatype while editing by using #editTemplate feature. Below is the frontend code:
But I am not able to put the validation on those controls while editing. So please guide me for the same.
Thanks
|
[app.component.html]
<ejs-grid #Grid id='Grid' [dataSource]='data' [allowResizing]='true'
[editSettings]='editSettings' [allowSorting]="true" [allowMultiSorting]='true'
(actionBegin)="onActionBegin($event)">
<e-columns>
<e-column field='id' isPrimaryKey='true' headerText='id' [visible]='false' textAlign='Left'>
</e-column>
<e-column field='name' [allowEditing]="false" headerText='Key' textAlign='Center'></e-column>
<e-column field='value' headerText='Value' [validationRules]='valuerules'>
<ng-template #editTemplate let-data>
<ng-container *ngIf="data.dataTypeText == propertyType.DATE">
<ejs-datepicker id="value" placeholder="Date" format='MM/dd/yyyy'
[(ngModel)]="gridData.value" floatLabelType='Never'></ejs-datepicker>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.BOOLEAN">
<ejs-checkbox id="value" [(ngModel)]="gridData.value"></ejs-checkbox>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.DECIMAL">
<ejs-numerictextbox id="value" format="#.##" [decimals]="2" [validateDecimalOnType]="true"
[(ngModel)]="gridData.value">
</ejs-numerictextbox>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.INTEGER">
<ejs-numerictextbox id="value" format="#" [decimals]="0" [validateDecimalOnType]="true" [(ngModel)]="gridData.value">
</ejs-numerictextbox>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.STRING">
<input class="e-input" id="value" [(ngModel)]="gridData.value" type="text" />
</ng-container>
<ng-container
*ngIf="data.dataTypeText == propertyType.STRING || data.dataTypeText == propertyType.LIST_OF_INTEGER || data.dataTypeText == propertyType.LIST_OF_STRING">
<input class="e-input" id="value"required [(ngModel)]="gridData.value" type="text" />
</ng-container>
</ng-template>
</e-column>
<e-column field='description' [allowEditing]="false" headerText='Description' textAlign='Left'>
</e-column>
<e-column headerText='Actions' textAlign='Center' [commands]="commands">
</e-column>
</e-columns>
</ejs-grid>
[app.component.ts]
public ngOnInit(): void {
this.valuerules = { required: true };
} |
Hello,
Thanks for the solution but now another problem is arriving in it. I want to remove the Validation Rule on the checkbox. As it is giving following error.
core.mjs:6469 ERROR TypeError: Cannot read properties of undefined (reading 'toString')
at Object.required (ej2-inputs.es2015.js:7349:107)
at FormValidator.isValid (ej2-inputs.es2015.js:7245:20)
at FormValidator.validateRules (ej2-inputs.es2015.js:7178:27)
at FormValidator.validate (ej2-inputs.es2015.js:6832:22)
at Edit.editFormValidate (ej2-grids.es2015.js:36891:51)
at GridComponent.focusOutHandler (ej2-grids.es2015.js:17021:33)
at ZoneDelegate.invokeTask (zone.js:434:1)
at Object.onInvokeTask (core.mjs:25437:1)
at ZoneDelegate.invokeTask (zone.js:433:1)
at Zone.runTask (zone.js:205:1)
So, please guide me how can I implement or remove the validation on checkbox.
Thanks
|
[app.component.html]
<ejs-grid #Grid id='Grid' [dataSource]='data' [allowResizing]='true'
[editSettings]='editSettings' [allowSorting]="true" [allowMultiSorting]='true'
(actionBegin)="onActionBegin($event)">
<e-columns>
<e-column field='id' isPrimaryKey='true' headerText='id' [visible]='false' textAlign='Left'>
</e-column>
<e-column field='name' [allowEditing]="false" headerText='Key' textAlign='Center'></e-column>
<e-column field='value' headerText='Value' [validationRules]='valuerules'>
<ng-template #editTemplate let-data>
<ng-container *ngIf="data.dataTypeText == propertyType.DATE">
<ejs-datepicker id="value" placeholder="Date" format='MM/dd/yyyy'
[(ngModel)]="gridData.value" floatLabelType='Never'></ejs-datepicker>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.BOOLEAN">
<ejs-checkbox [(ngModel)]="gridData.value"></ejs-checkbox> //removed the id property in the checkbox component
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.DECIMAL">
<ejs-numerictextbox id="value" format="#.##" [decimals]="2" [validateDecimalOnType]="true"
[(ngModel)]="gridData.value">
</ejs-numerictextbox>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.INTEGER">
<ejs-numerictextbox id="value" format="#" [decimals]="0" [validateDecimalOnType]="true" [(ngModel)]="gridData.value">
</ejs-numerictextbox>
</ng-container>
<ng-container *ngIf="data.dataTypeText == propertyType.STRING">
<input class="e-input" id="value" [(ngModel)]="gridData.value" type="text" />
</ng-container>
<ng-container
*ngIf="data.dataTypeText == propertyType.STRING || data.dataTypeText == propertyType.LIST_OF_INTEGER || data.dataTypeText == propertyType.LIST_OF_STRING">
<input class="e-input" id="value"required [(ngModel)]="gridData.value" type="text" />
</ng-container>
</ng-template>
</e-column>
<e-column field='description' [allowEditing]="false" headerText='Description' textAlign='Left'>
</e-column>
<e-column headerText='Actions' textAlign='Center' [commands]="commands">
</e-column>
</e-columns>
</ejs-grid>
[app.component.ts]
public ngOnInit(): void {
this.valuerules = { required: true };
}
|
core.mjs:6469 ERROR TypeError: Cannot read properties of null (reading 'parentElement')
at FormValidator.getErrorElement (ej2-inputs.es2015.js:7301:96)
at FormValidator.validateRules (ej2-inputs.es2015.js:7169:18)
at FormValidator.validate (ej2-inputs.es2015.js:6832:22)
at Edit.editFormValidate (ej2-grids.es2015.js:36891:51)
at InlineEdit.editFormValidate (ej2-grids.es2015.js:34982:41)
at InlineEdit.endEdit (ej2-grids.es2015.js:34991:42)
at InlineEdit.endEdit (ej2-grids.es2015.js:35384:15)
at Edit.endEditing (ej2-grids.es2015.js:36923:25)
at Edit.endEdit (ej2-grids.es2015.js:36836:14)
at GridComponent.
core.mjs:6469 ERROR TypeError: Cannot read properties of undefined (reading 'toString')
at Object.required (ej2-inputs.es2015.js:7349:107)
at FormValidator.isValid (ej2-inputs.es2015.js:7245:20)
at FormValidator.validateRules (ej2-inputs.es2015.js:7178:27)
at FormValidator.validate (ej2-inputs.es2015.js:6832:22)
at Edit.editFormValidate (ej2-grids.es2015.js:36891:51)
at InlineEdit.editFormValidate (ej2-grids.es2015.js:34982:41)
at InlineEdit.endEdit (ej2-grids.es2015.js:34991:42)
at InlineEdit.endEdit (ej2-grids.es2015.js:35384:15)
at Edit.endEditing (ej2-grids.es2015.js:36923:25)
at Edit.endEdit (ej2-grids.es2015.js:36836:14)
There is no problem in rendering the grid. Everything is fine, having issue in editing with validation Rule only.
Data is an array of object of the following type:
{
where "dataTypeText" = "DATE" or "STRING" or "BOOLEAN" or "INTEGER" or "DECIMAL" or "LIST_OF_INTEGER"
or "LIST_OF_STRING".
*all fields are string type. I am taking care of necessary type conversion to render the controls on "ActionBegin".
Hello ,
Please try to provide it and help me out from current situation. It is becoming difficult for me to wait for more than this.
Thanks
|
actionComplete(args) { //actionComplete event of Grid
if (args.requestType === 'beginEdit' || args.requestType === 'add') {
if (args.rowData.dataTypeText !== 'BOOLEAN') {
args.form.ej2_instances[0].addRules('value', { required: true });
}
}
}
|
Hello,
It worked.... I must say you have saved my efforts. But I had to remove [ValidationRule] on the column basis to get the success. Your sample did a great help.
Thanks a lot.