Skip to content

Commit 934818d

Browse files
⏫ Forwardport of #12739 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12739.patch (created by @zamoroka) based on commit(s): 1. 465e14b 2. 8bc807f 3. e9dcb03 Fixed GitHub Issues in 2.3-develop branch: - #6113: Validate range-words in Form component (UI Component) (reported by @robinhuy)
1 parent 8e77e2f commit 934818d

File tree

2 files changed

+47
-2
lines changed
  • app/code/Magento/Ui/view/base/web/js/lib/validation
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/validation

2 files changed

+47
-2
lines changed

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ define([
8484
],
8585
'range-words': [
8686
function (value, params) {
87-
return utils.stripHtml(value).match(/\b\w+\b/g).length >= params[0] &&
88-
value.match(/bw+b/g).length < params[1];
87+
var match = utils.stripHtml(value).match(/\b\w+\b/g) || [];
88+
89+
return match.length >= params[0] &&
90+
match.length <= params[1];
8991
},
9092
$.mage.__('Please enter between {0} and {1} words.')
9193
],
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable max-nested-callbacks */
7+
define([
8+
'Magento_Ui/js/lib/validation/rules'
9+
], function (rules) {
10+
'use strict';
11+
12+
describe('Magento_Ui/js/lib/validation/rules', function () {
13+
describe('"range-words" method', function () {
14+
it('Check on empty value', function () {
15+
var value = '',
16+
params = [1,3];
17+
18+
expect(rules['range-words'].handler(value, params)).toBe(false);
19+
});
20+
21+
it('Check on redundant words', function () {
22+
var value = 'a b c d',
23+
params = [1,3];
24+
25+
expect(rules['range-words'].handler(value, params)).toBe(false);
26+
});
27+
28+
it('Check with three words', function () {
29+
var value = 'a b c',
30+
params = [1,3];
31+
32+
expect(rules['range-words'].handler(value, params)).toBe(true);
33+
});
34+
35+
it('Check with one word', function () {
36+
var value = 'a',
37+
params = [1,3];
38+
39+
expect(rules['range-words'].handler(value, params)).toBe(true);
40+
});
41+
});
42+
});
43+
});

0 commit comments

Comments
 (0)