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

[Issue] Fix type when validating field using attribute rules #38774

Open
2 of 5 tasks
m2-assistant bot opened this issue May 29, 2024 · 7 comments · May be fixed by #38773
Open
2 of 5 tasks

[Issue] Fix type when validating field using attribute rules #38774

m2-assistant bot opened this issue May 29, 2024 · 7 comments · May be fixed by #38773
Labels
Area: Framework Component: Backend Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: PR in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@m2-assistant
Copy link

m2-assistant bot commented May 29, 2024

This issue is automatically created based on existing pull request: #38773: Fix type when validating field using attribute rules


Description (*)

If attribute based rules are used to specify validation of a field in HTML, incorrect type is used when validating.
For example, validation rule is ipv4 and has assigned a value of true and is processed as String, but should be Boolean instead.

<input name="field" ipv4="true" ... />

Related Pull Requests

N/A

Fixed Issues (if relevant)

N/A

Manual testing scenarios (*)

  1. create new form (for example on Homepage, custom-form.phtml)
  2. paste the following code:
<form class="form" action="#" id="custom-form" method="post">
    <fieldset class="fieldset">
    <div class="field required">
            <label class="label" for="custom-field"><span>Attribute Rule</span></label>
            <div class="control">
                <input name="custom-field" id="custom-field" title="Attribute Rule" value="ipv4" ipv4="true" class="input-text" type="text" />
            </div>
        </div>
    </fieldset>
</form>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Customer/js/block-submit-on-send": {
                "formId": "custom-form"
            }
        }
    }
</script>
  1. submit the form, error will be displayed on the field. When debugging the applied rule using the following command in rules method:
rules: function( command, argument ) {
...
              data = $.validator.normalizeRules(
                $.extend(
                    {},
                    $.validator.metadataRules(element),
                    $.validator.classRules( element ),
                    $.validator.attributeRules( element ),
                    $.validator.dataRules( element ),
                    $.validator.staticRules( element )
                ), element );

// debug the value
              if (!!$.validator.attributeRules(element) && Object.keys($.validator.attributeRules(element)).length > 0) {
                console.log($.validator.attributeRules(element));
              }
...
  • Actual value: String
    {ipv4: 'true'}
  • Expected value: boolean
    {ipv4: true}

Questions or comments

The PR has been elaborated in my article which describes the issue in more details: Deep Dive into Validation Rules

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)
@m2-assistant m2-assistant bot linked a pull request May 29, 2024 that will close this issue
6 tasks
@engcom-Bravo engcom-Bravo added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label May 29, 2024
@m2-community-project m2-community-project bot added the Priority: P3 May be fixed according to the position in the backlog. label May 29, 2024
@engcom-Bravo engcom-Bravo added Reported on 2.4.x Indicates original Magento version for the Issue report. and removed Priority: P3 May be fixed according to the position in the backlog. labels May 29, 2024
@engcom-November engcom-November self-assigned this May 31, 2024
Copy link
Author

m2-assistant bot commented May 31, 2024

Hi @engcom-November. 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).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.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. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link
Contributor

Hello @dvrgoc,

Thank you for the report and collaboration!

We are able to get the actual result, that is ipv4 value is string in jquery.validate.js.
Please refer the screenshot:
image

But can you mention the issue you are facing due to change in datatype.

@engcom-November engcom-November added the Issue: needs update Additional information is require, waiting for response label May 31, 2024
@dvrgoc
Copy link

dvrgoc commented Jun 4, 2024

HI @engcom-November

that is correct, this is datatype issue.

While I was working with other methods of implementing the validation rules, all other rules return Boolean, not String.

image

Please read my article which covers the topic - Deep Dive into Validation Rules

If you have any questions, let me know.

@engcom-November
Copy link
Contributor

Hello @dvrgoc,

Thanks for the update.

I agree with this, inconsistent return type compared to rest of the methods is not a good practice and might cause error further down the line.
Hence confirming this.

@engcom-November engcom-November added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: Backend Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Framework labels Jun 4, 2024
@m2-community-project m2-community-project bot added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: needs update Additional information is require, waiting for response labels Jun 4, 2024
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-12079 is successfully created for this GitHub issue.

Copy link
Author

m2-assistant bot commented Jun 4, 2024

✅ Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@github-jira-sync-bot
Copy link

❌ You don't have permission to export this issue.

@m2-community-project m2-community-project bot added the Priority: P3 May be fixed according to the position in the backlog. label Jun 5, 2024
@engcom-Bravo engcom-Bravo removed the Priority: P3 May be fixed according to the position in the backlog. label Jun 5, 2024
@engcom-Bravo engcom-Bravo added the Priority: P3 May be fixed according to the position in the backlog. label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Component: Backend Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: PR in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Pull Request In Progress
Development

Successfully merging a pull request may close this issue.

4 participants