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

Can't validate fields with name like "fieldname[]" #140

Open
hanialaraj opened this issue Apr 9, 2015 · 2 comments
Open

Can't validate fields with name like "fieldname[]" #140

hanialaraj opened this issue Apr 9, 2015 · 2 comments

Comments

@hanialaraj
Copy link

If you have select element like this:
<select name="degree[]">
<option value="">Select</option>
<option value="High School" >High School</option>
<option value="Diploma" >Diploma</option>
<option value="BA" >BA</option>
</select>

new FormValidator('applyform', [{
name: 'degree[]',
display: 'Degree',
rules: 'required'}], function(errors, e){
/* if(errors.length > 0) is always true even if "degree[]" select is selected*/
});

Fix suggestion, inside attributeValue plugin function, before the last "return", I added

if ((attributeName == 'value') && (element.length > 0) && (element[0].type === 'select-one')) {
_v = new Array();
for (i = 0, elementLength = element.length; i < elementLength; i++) {
if(element[i][attributeName] && element[i][attributeName].length > 0){
_v.push(element[i][attributeName]);
}else{
return ''; // stop looping, found empty value!
}
}
return _v; // return array of collected values
}

@rickharrison
Copy link
Owner

A pull request would be much appreciated in this area :)

@shehriyarnadeem
Copy link

Hi, @rickharrison I would like to work on this issue. Can you please assign me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants