Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On checkout cart submit, pattern regex validation fails #23766

Closed
vahir2016 opened this issue Jul 18, 2019 · 4 comments
Closed

On checkout cart submit, pattern regex validation fails #23766

vahir2016 opened this issue Jul 18, 2019 · 4 comments
Labels
Component: Checkout Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@vahir2016
Copy link
Contributor

Preconditions (*)

  1. Magento ver. 2.2.6

Steps to reproduce (*)

  1. On checkout cart page, use input type text for quantity and use pattern like "[0-9]"
  2. Bind jquery submit to submit form on input change
  3. In broswer console, you will see : "param.test is not a function"
  4. 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 (*)

  1. Form submits

Actual result (*)

  1. 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)

Sélection_078

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.

@m2-assistant
Copy link

m2-assistant bot commented Jul 18, 2019

Hi @vahir2016. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@vahir2016 do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jul 18, 2019
@engcom-Bravo engcom-Bravo self-assigned this Jul 18, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jul 18, 2019

Hi @engcom-Bravo. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Bravo engcom-Bravo added Component: Checkout Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Jul 18, 2019
@ghost ghost unassigned engcom-Bravo Jul 18, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Bravo
Thank you for verifying the issue. Based on the provided information internal tickets MC-18258 were created

Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jul 18, 2019
magento-engcom-team added a commit that referenced this issue Sep 26, 2019
 - Merge Pull Request #23767 from vahir2016/magento2:fix_form_validation_pattern
 - Merged commits:
   1. 8488c07
magento-engcom-team added a commit that referenced this issue Sep 26, 2019
…op expedited

Accepted Community Pull Requests:
 - #24665: Refactor apply options of sales rule to it's own source model to simplify extending it (by @Bartlomiejsz)
 - #24634: fixed getting error in console while selecting all downloadable links #24633 (by @rani-webkul)
 - #24153: Fix config backend model PDF file name extension (by @Vinai)
 - #23767: #23766 - fix pattern validation on form submit (by @vahir2016)
 - #24030: 24025 add caching for magento product version (by @davidverholen)


Fixed GitHub Issues:
 - #24633: Getting error in console while selecting all downloadable links  (reported by @rani-webkul) has been fixed in #24634 by @rani-webkul in 2.3-develop branch
   Related commits:
     1. 66b7785

 - #24025: Slow Performance of ProductMetadata::getVersion (reported by @beberlei) has been fixed in #24030 by @davidverholen in 2.3-develop branch
   Related commits:
     1. f0856e8
     2. ed1fb03
     3. b2ca7c8
     4. b397814
@krzksz
Copy link
Contributor

krzksz commented Nov 19, 2019

I believe this is fixed by 8488c07

@krzksz krzksz closed this as completed Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Checkout Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

4 participants