Skip to content
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

Error in not validating array's of inputs correctly. #2326

Closed
thejoker-dev opened this issue Apr 29, 2020 · 4 comments · May be fixed by #2431
Closed

Error in not validating array's of inputs correctly. #2326

thejoker-dev opened this issue Apr 29, 2020 · 4 comments · May be fixed by #2431
Labels
stale Used to mark stale issues

Comments

@thejoker-dev
Copy link

Subject of the issue

The error occurs in the instance of validating a form with array's of equal inputs, it only validates the first element found within the form.

Your environment

  • version of jquery-validate: 1.19.1
  • version of jquery: 3.4.1
  • which browser and its version: Google Chrome v81.0.4044.122 (Build oficial) (64 bits)

Steps to reproduce

http://jsfiddle.net/thejoker_dev/p6zs51v8/

Expected behaviour

It should validate all types of inputs, including those that are arrays of themselves.

Actual behaviour

Validates only the first input of the array with the same name, leaving the rest unvalidated.

Attached jquery-validate.js file modified on line 465 (checkForm function) which I leave below and it works without problems!

checkForm: function() { this.prepareForm(); for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) { var checkingElements = this.findByName( elements[i].name ).not(this.settings.ignore); if (checkingElements.length !== undefined && checkingElements.length > 1) { for (var cnt = 0; cnt < checkingElements.length; cnt++) { this.check( checkingElements[cnt] ); } } else { this.check( elements[i] ); } } return this.valid(); }

Attached jquery-validate.js file modified on line 465 (checkForm function) which I leave below and it works without problems!

jquery.validate.zip

@bytestream
Copy link
Member

The is a long standing issue and linked to many in the past - #2046 #2102 #1226

Linked PR #2000

@adnanhaider80
Copy link

JqueryValidation filtering same name elements under rules cache, I just comment the rulesCache. It works for me.
https://stackoverflow.com/a/69452906/1939258

@shibin-pb
Copy link

shibin-pb commented Apr 30, 2022

How to add remote method validation to array of inputs using class name
`

input type="text" id="ApplyAuthTCSCDT1" name="ApplyAuthTCSCDT[1]" class="form-control scdDateTime formPadding scdDataDT" required=""
input type="text" id="ApplyAuthTCSCDT2" name="ApplyAuthTCSCDT[2]" class="form-control scdDateTime formPadding scdDataDT" required=""

input type="text" id="ApplyConfirmpnSCTCDT1" name="ApplyConfirmpnSCTCDT[1]" class="form-control scdDateTime formPadding scdDataDT" required=""
input type="text" id="ApplyConfirmpnSCTCDT2" name="ApplyConfirmpnSCTCDT[2]" class="form-control scdDateTime formPadding scdDataDT" required=""

input type="text" id="RemoveAuthTCSCDT1" name="RemoveAuthTCSCDT[1]" class="form-control scdDateTime formPadding scdDataDT" required=""
input type="text" id="RemoveAuthTCSCDT2" name="RemoveAuthTCSCDT[2]" class="form-control scdDateTime formPadding scdDataDT" required=""

`

Have tried to use the following jquery validation rule function but getting error Uncaught TypeError: e.nodeName is undefined. Exception occurred when checking element ApplyConfirmpnSCTCDT1, check the 'remote' method. .

The following are the jquery code.

$(".scdDataDT").each(function() {
$(this).rules('add', {
required: true,
remote: {
url: "check-time.php",
type: "POST",
async: false,
data: {
scdDT: function() {
console.log($(this).val()) ;
return $( "#"+$(this).attr("id")).val();
},
pbId: function() {
return $( "#SCDApplyRemovePBId" ).val();
},
pbNo: function() {
return $( "#SCDApplyRemovePBNo" ).val();
}
}
},
messages: {
required: "*",
remote:"#"
}
});
});

@github-actions
Copy link

This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automatically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up.
Thank you for contributing :)

@github-actions github-actions bot added the stale Used to mark stale issues label Jun 30, 2022
@bytestream bytestream linked a pull request Jul 1, 2022 that will close this issue
@github-actions github-actions bot closed this as completed Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Used to mark stale issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants