Description
Preconditions (*)
- Magento ver. 2.2.6
Steps to reproduce (*)
- On checkout cart page, use input type text for quantity and use pattern like "[0-9]"
- Bind jquery submit to submit form on input change
- In broswer console, you will see : "param.test is not a function"
- The form will not submit
<input id="cart-<?= /* @escapeNotVerified */ $_item->getId() ?>-qty" name="cart[<?= /* @escapeNotVerified */ $_item->getId() ?>][qty]" data-cart-item-id="<?= $block->escapeHtml($_item->getSku()) ?>" value="<?= /* @escapeNotVerified */ $block->getQty() ?>" type="text" size="4" pattern="^(0|[1-9][0-9]*)$" title="<?= $block->escapeHtml(__('Qty')) ?>" class="input-text qty" data-validate="{required:true,'validate-greater-than-zero':true}" data-role="cart-item-qty"/>
require([ 'jquery', ], function($) { $('#form-validate .input-text.qty').on('change', function() { console.log('here'); $('#form-validate').submit(); }); });
Expected result (*)
- Form submits
Actual result (*)
- Uncaught TypeError: param.test is not a function
at $.validator. (validation.js:541)
at $.validator.check (jquery.validate.js:556)
at $.validator.checkForm (jquery.validate.js:372)
at $.validator.form (jquery.validate.js:359)
at jQuery.fn.init.valid (jquery.validate.js:108)
at $...isValid (validation.js:1845)
at $...isValid (jquery-ui.js:402)
at HTMLFormElement. (jquery-ui.js:494)
at Function.each (jquery.js:370)
at jQuery.fn.init.each (jquery.js:137)
I fixed the problem with this solution :
in magento/lib/web/mage/validation.js line 538
replace :
/* eslint-enable max-len */ 'pattern': [ function (value, element, param) { return this.optional(element) || param.test(value); }, $.mage.__('Invalid format.') ],
by
/* eslint-enable max-len */ 'pattern': [ function (value, element, param) { return this.optional(element) || new RegExp(param).test(value); }, $.mage.__('Invalid format.') ],
I am doing a pull request for this.