-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
I cannot configure a form field with validation range-words, it different than validate-number-range
Preconditions
- Magento 2
Steps to reproduce
- 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>
- Flush cache.
- In Admin, open any product and click "New Category"
- 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 ?