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

Magento Ui form validator message callback not supported #20078

Closed
floorz opened this issue Jan 4, 2019 · 5 comments
Closed

Magento Ui form validator message callback not supported #20078

floorz opened this issue Jan 4, 2019 · 5 comments
Assignees
Labels
Component: Ui Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line 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.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@floorz
Copy link
Contributor

floorz commented Jan 4, 2019

Preconditions (*)

  1. 2.1.x, 2.2.x, 2.3.x

Steps to reproduce (*)

  1. Create a new validation rule using the Magento_Ui::js/lib/validation/validator.js, using a callback as the validator's message.
  1. Add the new validation rule to a form field (in my case, one of the checkout address fields)
  2. Use the field in the form it resides, making it fail validation

Expected result (*)

  1. Seeing a failed validation message for that field

Actual result (*)

  1. Javascript Error: Uncaught TypeError: msg.replace is not a function
  2. Error occurance happens at https://github.com/magento/magento2/blob/2.1/app/code/Magento/Ui/view/base/web/js/lib/validation/validator.js#L43-L45
    javascript-type-error
  3. Any case where the message is a callback function, this error seems like it will happen

Additional Notes

  1. Jquery validation already seems to handle this scenario of the validation message being a callback. It checks if the message is of type function, and if so, calls it, setting the this context appropriately.

Proposed Solution

  1. Adding the same sort of type check that jquery does, and reassigning the message variable to the result of calling the message callback.

Example (in Magento_Ui::js/lib/validation/validator::vailidate()):

if (typeof message === 'function') {
    message = message.call(rule);
}
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Jan 4, 2019

Hi @floorz. 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-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@floorz do you confirm that you was 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 Jan 4, 2019
@shikhamis11 shikhamis11 added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Component: Ui labels Jan 5, 2019
@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 Jan 5, 2019
@magento-engcom-team
Copy link
Contributor

@shikhamis11 Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97459, MAGETWO-97460 were created

@floorz
Copy link
Contributor Author

floorz commented Jan 8, 2019

@shikhamis11 are one of those internal tickets for 2.2.x and the other for 2.3.x ?

@magento-engcom-team
Copy link
Contributor

Hi @floorz. Thank you for your report.
The issue has been fixed in #20079 by @floorz in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Mar 5, 2019
@magento-engcom-team
Copy link
Contributor

Hi @floorz. Thank you for your report.
The issue has been fixed in #20107 by @floorz in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.9 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Ui Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line 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.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

3 participants