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
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
-
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:_createfunction is called. But in my case does not.Anthony– Anthony2018年02月05日 09:59:35 +00:00Commented 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– Asrar2018年02月05日 11:00:44 +00:00Commented 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– Anthony2018年02月05日 11:27:01 +00:00Commented Feb 5, 2018 at 11:27