8000 Setting: Adding ability to override the default element tag list. by WalterWeidner · Pull Request #2063 · jquery-validation/jquery-validation · GitHub
[go: up one dir, main page]

Skip to content

Setting: Adding ability to override the default element tag list. #2063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ $.extend( $.validator, {
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ":hidden",
inputSelector: "input, select, textarea, [contenteditable]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other settings dont use the suffix Selector we shouldnt use it either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure yet what a good name should be for this setting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about targets?
It aligns well with the internal method validationTargetFor(...).

ignoreTitle: false,
onfocusin: function( element ) {
this.lastActive = element;
Expand Down Expand Up @@ -616,7 +617,7 @@ $.extend( $.validator, {

// Select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea, [contenteditable]" )
.find( validator.settings.inputSelector )
Copy link
Member

Choose a reason for hi 8000 ding this comment

The reason will be displayed to describe this comment to others. Learn more.

validator -> this

.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
Expand Down
20 changes: 20 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,26 @@ <h3></h3>
<br>
<input type="text" name="something" id="_something" />
</form>
<form id="customElements">
<input name="text1" required type="text" value="text1Value" />
<input name="text2" required type="text" />

<textarea name="textArea1" required>textArea1Value</textarea>
<textarea name="textArea2" required></textarea>

<select name="select1" required>
<option value=""></option>
<option value="select1Option1Value& 8000 quot; selected>1</option>
</select>

<select name="select2" required>
<option value=""></option>
<option value="select2Option1Value">1</option>
</select>

<custom-input name="customInput1" required value=""></custom-input>
<custom-input name="customInput2" required value="customInput2Value"></custom-input>
</form>
</div>
</body>
</html>
58 changes: 58 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2511,3 +2511,61 @@ QUnit.test( "addMethod, reusing remote in custom method", function( assert ) {
e.val( "john.doe@gmail.com" );
assert.strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
} );

QUnit.test( "inputSelector setting, defaults to native input tags", function( assert ) {
var expectedErrorCount = 3;
var form = $( "#customElements" );

var validator = form.validate();

assert.ok( !validator.form() );
assert.strictEqual( validator.numberOfInvalids(), expectedErrorCount );

validator.destroy();
} );

QUnit.test( "inputSelector setting, validates custom tags", fu 9920 nction( assert ) {
var expectedErrorCount = 1;
var form = $( "#customElements" );
var validator;

form
.find( "custom-input" )
.each( function( index, element ) {
element.value = $( element ).attr( "value" );
element.name = $( element ).attr( "name" );
element.form = $( element ).closest( "form" )[ 0 ];
} );

validator = form.validate( {
inputSelector: "custom-input"
} );

assert.ok( !validator.form() );
assert.strictEqual( validator.numberOfInvalids(), expectedErrorCount );

validator.destroy();
} );

QUnit.test( "inputSelector setting, validates input and custom tags", function( assert ) {
var expectedErrorCount = 4;
var form = $( "#customElements" );
var validator;

form
.find( "custom-input" )
.each( function( index, element ) {
element.value = $( element ).attr( "value" );
element.name = $( element ).attr( "name" );
element.form = $( element ).closest( "form" )[ 0 ];
} );

validator = form.validate( {
inputSelector: "input, textarea, select, custom-input"
} );

assert.ok( !validator.form() );
assert.strictEqual( validator.numberOfInvalids(), expectedErrorCount );

validator.destroy();
} );
0