0

Does anybody know how to solve this problem:

i'm trying to add custom field validation. Chrome console does not have any errors.

app/code/Company/Module/view/frontend/web/js/view/payment/script.js

define(
    [
        "jquery",
        "mage/validation"
    ],
    function ($) {
            console.log('fire1');
        $.validator.addMethod('test-req', function(v) {
            console.log('fire2');
            return false;
        }, 'The amount you entered is too low.');
    }
);

src/app/code/Company/Module/view/frontend/web/template/payment/form_additional.html

<input class='required test-req' type='text'  data-bind="value: checker" placeholder='Enter the value' minlength='10' maxlength='10'/>

On page loading fire1 always works. But fire2 is never called. What could be a problem here?

1 Answer 1

1

take a look at how Magento 2 validations were added in: lib/web/prototype/validation.js That should give you some hints how to add custom validations.

Also take a look here https://magento.stackexchange.com/a/192407/50597

3
  • The problem is that i did like manual says and it does not work for me. Normally when you press submit button src/lib/web/mage/validation.js:_create function is called. But in my case does not.
    – Anthony
    Feb 5, 2018 at 9:59
  • So, did you fixe the issue yet? If so, please share your fix. Otherwise, go ahead with more queries :).
    – Asrar
    Feb 5, 2018 at 11:00
  • i found that even standard validation is not working. Do you know is there some widget for form initialisation?
    – Anthony
    Feb 5, 2018 at 11:27

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.