Core: Fix lint errors, add test

This commit is contained in:
Daniel Orner
2015-02-27 15:51:19 -05:00
committed by Daniel Orner
parent 3d0cd6f2a5
commit b76c83e742
3 changed files with 28 additions and 6 deletions

View File

@@ -555,16 +555,22 @@ $.extend( $.validator, {
.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
if ( !this.name && validator.settings.debug && window.console ) {
var name = this.name || $(this).attr("name"); // for contenteditable
if ( !name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this );
}
// set form expando on contenteditable
if (this.hasAttribute("contenteditable")) {
this.form = $(this).closest("form")[0];
}
// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
return false;
}
rulesCache[ this.name ] = true;
rulesCache[ name ] = true;
return true;
} );
},
@@ -608,10 +614,9 @@ $.extend( $.validator, {
return element.validity.badInput ? false : $element.val();
}
if (element.hasAttribute('contenteditable')) {
if (element.hasAttribute("contenteditable")) {
val = $element.text();
}
else {
} else {
val = $element.val();
}
if ( typeof val === "string" ) {

View File

@@ -382,6 +382,13 @@
<label for="testForm21!#$%&'()*+,./:;<=>?@[\]^`{|}~">Input text</label>
<input type="text" name="testForm21!#$%&'()*+,./:;<=>?@[\]^`{|}~" id="testForm21!#$%&'()*+,./:;<=>?@[\]^`{|}~" required minlength="15">
</form>
<form id="contenteditableForm">
<div contenteditable id="contenteditableNumberInvalid" data-rule-number="true" name="field1">ABC</div>
<div contenteditable id="contenteditableNumberValid" data-rule-number="true" name="field2">123</div>
<div contenteditable id="contenteditableRequiredInvalid" data-rule-required="true" name="field3"></div>
<div contenteditable id="contenteditableRequiredValid" data-rule-required="true" name="field3">Some text</div>
<input id="contenteditableInput" type="text" data-rule-number="true" name="field4" value="ABC" />
</form>
</div>
</body>
</html>

View File

@@ -928,6 +928,16 @@ test( "bypassing validation on form submission", function() {
equal( $v.numberOfInvalids(), 1, "Validation failed correctly" );
} );
test( "works on contenteditable fields", function(assert) {
var form = $( "#contenteditableForm" );
form.valid();
assert.hasError($('#contenteditableNumberInvalid'), 'Please enter a valid number.');
assert.hasError($('#contenteditableRequiredInvalid'), 'This field is required.');
assert.hasError($('#contenteditableInput'), 'Please enter a valid number.');
assert.noErrorFor($('#contenteditableNumberValid'));
assert.noErrorFor($('#contenteditableRequiredValid'));
});
module( "misc" );
test( "success option", function() {