Skip to content

Commit a0ed6f8

Browse files
committed
Core: Fix normalization for rangelength attribute value
This regressed at some point, probably when rules-as-data-attributes where introduced, since those are automatically parsed as JSON. For the unprocessed attributes, the array brackets have to be removed. Also fixes the milk demo, which specified rangelength as the message, instead of minlength, which it actually uses. Fixes jquery-validation#1087
1 parent d09a5ee commit a0ed6f8

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

demo/milk/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
},
7777
password: {
7878
required: "Provide a password",
79-
rangelength: jQuery.validator.format("Enter at least {0} characters")
79+
minlength: jQuery.validator.format("Enter at least {0} characters")
8080
},
8181
password_confirm: {
8282
required: "Repeat your password",

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ $.extend($.validator, {
985985
if ( $.isArray(rules[this]) ) {
986986
rules[this] = [ Number(rules[this][0]), Number(rules[this][1]) ];
987987
} else if ( typeof rules[this] === "string" ) {
988-
parts = rules[this].split(/[\s,]+/);
988+
parts = rules[this].replace(/[\[\]]/g, "").split(/[\s,]+/);
989989
rules[this] = [ Number(parts[0]), Number(parts[1]) ];
990990
}
991991
}

test/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ <h2 id="qunit-userAgent"></h2>
155155
<input name="testForm12text" id="testForm12text" data-rule-required="true" />
156156
</form>
157157

158+
<form id="testForm13">
159+
<select id="cars-select" name="cars" title="Please select at least two cars, but no more than three" required rangelength="[2,3]" multiple="multiple">
160+
<option value="m_sl">Mercedes SL</option>
161+
<option value="o_c">Opel Corsa</option>
162+
<option value="vw_p">VW Polo</option>
163+
<option value="t_s">Titanic Skoda</option>
164+
</select>
165+
</form>
166+
158167
<form id="dataMessages">
159168
<input name="dataMessagesName" id="dataMessagesName" class="required" data-msg-required="You must enter a value here" />
160169
</form>

test/rules.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,11 @@ test("rules(), add messages", function() {
296296
$("#firstnamec").valid();
297297
equal(v.errorList.length, 0);
298298
});
299+
300+
test( "rules(), rangelength attribute as array", function() {
301+
$("#testForm13").validate();
302+
deepEqual( $("#cars-select").rules(), {
303+
required: true,
304+
rangelength: [2,3]
305+
});
306+
});

0 commit comments

Comments
 (0)