0

I want to add a custom validation on my custom UI grid.

Logic is that the Max qty must be greater than the Min qty. This is working fine for the UI form, but not working for UI grid mass action.

Screenshot attached for reference.

form-custom-validation.png grid-custom-validation.png

Working code for UI form is below:

require(
        [
    'Magento_Ui/js/lib/validation/validator',
    'jquery',
    'mage/translate'
], function(validator, $){
    validator.addRule(
        'validate-minmax',
        function (value) {
            var minQty = $("[name='min_qty']").val();
            var maxQty = $("[name='max_qty']").val();
            if (minQty == 0 && maxQty == 0) {
                return true;
            }
            if (minQty > 0 || maxQty > 0) {
                if (minQty >= maxQty) {
                    return false;
                }
                if (minQty < maxQty) {
                    return true;
                }
            }
        }
        ,$.mage.__('Max qty must be greater than min qty.')
                );
        });

What changes should I make in my code to make it work for UI grid inline edit? Should I validate it in controller (on server side)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.