I have created a custom validation rule in my admin ui form using the below link


If I use a direct condition then it is working fine. I need to call a ajax function and based on that response I need to validate the field. In this case it is always shows error. Not depend on the ajax response. It returns a false before completing the ajax.

Here is my js code

], function(validator, $){
            function (value) {
                // if (value == 'PE') {
                //     return true;
                // }
                // return false;
                var url = BASE_URL.split('admin/')[0];
                    url:  url+"admin/abc/prefix/Validate",
                    showLoader: true,
                    data: {'group_code':value},
                    type: "POST",
                    dataType : 'json',
                    success: function(result){
                        return result.success;
            $.mage.__('Prefix Code already exist.')

Please help me to fix this

1 Answer 1

Add async: false in $.ajax({...})
  • Tried it, But it is not worked Jan 17 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.