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?

asked Feb 4, 2018 at 23:41

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

answered Feb 5, 2018 at 1:51
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. Commented 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 :). Commented 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? Commented Feb 5, 2018 at 11:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.