Hello,
I am trying to use custom rule validation as described here :-
I would like to use data:Object within the validation Callback.
Here is my below code snippet-
HTML <dx-data-grid..........>
<dxi-column dataField="deliveryQuantity" dataType="number" [allowEditing]="false"
cellTemplate="deliveryQuantityTemplate"
[caption]="'app.orderDetails.columns.deliveryQuantity' | translate">
<div *dxTemplate="let cell of 'deliveryQuantityTemplate'" class="dx-cell-focus-disabled">
<dx-number-box
[valueChangeEvent]="'keyup'"
[(value)]="cell.data.deliveryQuantity"
required>
<dx-validator>
<dxi-validation-rule type="custom" [reevaluate]="true"
[validationCallback]="customDeliveryQuantityValidationCallback">
</dxi-validation-rule>
</dx-validator>
</dx-number-box>
</div>
</dx-data-grid.>
I understand reading the documentation that the data object in the validation callback is only present when used directly with the data grid itself. I would like to know what could be the other possible solution to fetch the current row values. In my *.ts file , I have below block code of shortened code, which doesnt work ofcourse.
JavaScriptcustomDeliveryQuantityValidationCallback(): boolean {
console.log(data);
if (this.outGoingGoodsInfo.length === 1) {
if (event.data.orderedQuantity === 1) {
return true;
}
return false;
}
Any help is appreciated.
Regards
Akshay
Hi,
Validation rules can be defined using the columns.validationRules option if editCellTemplate is used (see Customize Editors). At the same time, it's not clear why cellTemplate is necessary in your case. Do you need to enable editing and always display editors for a particular column? If so, use editCellTemplate and set showEditorAlways to "true".
If your idea is different, please describe why it's necessary to use cellTemplate with validation in greater detail.
We look forward to your reply.
Hi Artem.
Thanks for your response.
Well, this is what I tried based on your reply. I cannot get the error message to pop up in the given field. It only becomes slight red when there is an error input. Along with the code below, also find the screenshot attached along with this.
<dx-data-grid..........> <dxi-column dataField="deliveryQuantity" dataType="number" [allowEditing]="true" editCellTemplate="deliveryQuantityTemplate" [showEditorAlways]="true" [caption]="'app.orderDetails.columns.deliveryQuantity' | translate"> <dxi-validation-rule type="custom" [reevaluate]="true" [validationCallback]="customDeliveryQuantityValidationCallback"> </dxi-validation-rule>> </dxi-column> <div *dxTemplate="let cell of 'deliveryQuantityTemplate'" class="dx-cell-focus-disabled"> <dx-number-box [valueChangeEvent]="'keyup'" [(value)]="cell.value" required> </dx-number-box> </div> </dx-data-grid.>
In the .ts file
customDeliveryQuantityValidationCallback(): boolean { event.rule.isValid = false; event.rule.message = 'invalid input'; return false; }
Also, when I remove the focus from the field, the field is moved back to its initial value. Do I need to reset the value manually to the latest one after every input.
Please suggest.
Regards!