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.
// 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:
var atleastonefilled = $('input:not([type="submit"]').filter(function () { return $.trim(this.value) !== ''; }).length > 0;
Comments
Post a Comment