Skip to content

Validate range-words in Form component (UI Component) #6113

@robinhuy

Description

@robinhuy

I cannot configure a form field with validation range-words, it different than validate-number-range

Preconditions

  1. Magento 2

Steps to reproduce

  1. Edit {Magento root directory}/app/code/Magento/Catalog/view/adminhtml/ui_component/new_category_form.xml:
    In node with '<field name="name"' replace

<rule name="required-entry" xsi:type="boolean">true</item>

to

<rule name="range-words" xsi:type="array">
<item name="0" xsi:type="number">1</item>
<item name="1" xsi:type="number">3</item>
</rule>

  1. Flush cache.
  2. In Admin, open any product and click "New Category"
  3. Enter any value in "Category Name" field, set any "Parent Category" and press "Create Category"

Expected result

Category Name is validated and Category is created (or correct error message is displayed, if validation fails)

Actual result

Nothing happens explicitly. Error message appers in browser console.

When I test above code, it fired a bug in Chrome Console:
rules.js:78 Uncaught TypeError: Cannot read property 'length' of null

In rules.js

"range-words": [
    function(value, params) {
    return utils.stripHtml(value).match(/\b\w+\b/g).length >= params[0] &&
        value.match(/bw+b/g).length < params[1];
    },
    $.mage.__('Please enter between {0} and {1} words.')
]

Why the regex pattern check with params[0] and params[1] is different?

This is my fault or Magento bug and how to use range-words validation ?

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions