Skip to content

Commit a436634

Browse files
mlynchjzaefferer
authored andcommitted
Added pseudo selector for text input types to fix issue with default empty type attribute. Added tests and some test markup. Fixes jquery-validation#217
1 parent 02b10a6 commit a436634

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

jquery.validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ $.extend($.validator, {
323323
}
324324
}
325325
$(this.currentForm)
326-
.validateDelegate("[type='text'], [type='password'], [type='file'], select, textarea, " +
326+
.validateDelegate(":text, [type='password'], [type='file'], select, textarea, " +
327327
"[type='number'], [type='search'] ,[type='tel'], [type='url'], " +
328328
"[type='email'], [type='datetime'], [type='date'], [type='month'], " +
329329
"[type='week'], [type='time'], [type='datetime-local'], " +

test/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ <h2 id="qunit-userAgent"></h2>
149149
<input required type="text" name="testForm11Text" id="testForm11text1" />
150150
</form>
151151

152+
<form id="testForm12">
153+
<!-- empty "type" attribute -->
154+
<input name="testForm12text" id="testForm12text" class="{required:true}" />
155+
</form>
156+
152157
<div id="simplecontainer">
153158
<h3></h3>
154159
</div>

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,20 @@ test("validate radio on click", function() {
11771177
errors(0);
11781178
});
11791179

1180+
test("validate input with no type attribute, defaulting to text", function() {
1181+
function errors(expected, message) {
1182+
equal(expected, v.size(), message );
1183+
}
1184+
var v = $("#testForm12").validate();
1185+
var e = $("#testForm12text");
1186+
errors(0);
1187+
e.valid();
1188+
errors(1);
1189+
e.val('test');
1190+
e.trigger('keyup');
1191+
errors(0);
1192+
});
1193+
11801194
test("ignore hidden elements", function(){
11811195
var form = $('#userForm');
11821196
var validate = form.validate({

0 commit comments

Comments
 (0)