javascript - Collect data from inputs into array for validation -


i looking way loop through group of inputs, appending data each array might check see if array empty, allowing me validate if 1 or more of inputs has been filled out. using parsley validation, customer wants way ensure @ least 1 of these elements filled out.

currently have working giant jquery requirement/rules setup. feel clunky , other idea save space , time.

my jsfiddle

// validate form     $("#signupform").validate({     rules: {         telephone: {             required: function (element) {                 if (($("#mobile").val().length > 0) || ($("#olb").val().length > 0) || ($("#ach").val().length > 0)|| ($("#internet").val().length > 0) || ($("#paper").val().length > 0) ) {                     return false;                 } else {                     return true;                 }             }         },         mobile: {             required: function (element) {                 if (($("#telephone").val().length > 0) || ($("#olb").val().length > 0) || ($("#ach").val().length > 0)|| ($("#internet").val().length > 0) || ($("#paper").val().length > 0) ) {                     return false;                 } else {                     return true;                 }              }         },         olb: {             required: function (element) {                 if (($("#telephone").val().length > 0) || ($("#mobile").val().length > 0) || ($("#ach").val().length > 0)|| ($("#internet").val().length > 0) || ($("#paper").val().length > 0) ) {                     return false;                 } else {                     return true;                 }             }         },         ach: {             required: function(element) {                 if (($("#telephone").val().length > 0) || ($("#olb").val().length > 0) || ($("#mobile").val().length > 0)|| ($("#internet").val().length > 0) || ($("#paper").val().length > 0) ) {                     return false;                 } else {                     return true;                 }             }         },         internet: {             required: function(element) {                 if (($("#telephone").val().length > 0) || ($("#olb").val().length > 0) || ($("#ach").val().length > 0)|| ($("#mobile").val().length > 0) || ($("#paper").val().length > 0) ) {                     return false;                 } else {                     return true;                 }             }         },         paper: {             required: function(element) {                 if (($("#telephone").val().length > 0) || ($("#olb").val().length > 0) || ($("#ach").val().length > 0)|| ($("#internet").val().length > 0) || ($("#mobile").val().length > 0) ) {                     return false;                 } else {                     return true;                 }             }         }     } }); 

this doesn't fit validation plugin, here's simple solution:

http://jsfiddle.net/ykrdh/

var atleastonefilled = $('input:not([type="submit"]').filter(function () {     return $.trim(this.value) !== ''; }).length > 0; 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -