Skip to content

read values for required grouped "select" input #141

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@
return;
}

// Added to check if a required grouped fields have values
// Grouped filed example: <select name="degree[]">...</..> (one or more field with name="degree[]" attribute)
if ((attributeName == 'value') && (element.length > 0) && (element[0].type === 'select-one')) {
var _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 an empty value! either return all values or nothing
}
}
/**
* @return: array of collected values.
* @TODO: However, this returned value can be used to check if required
* @TODO: field is set or not (when option rules: 'required' for a field). For other rules, returned value
* @TODO: need to be handled
*/
return _v;
}

return element[attributeName];
};

Expand Down