Last active
August 29, 2015 14:04
-
-
Save viniciusban/b18bf1464521eb9dedfc to your computer and use it in GitHub Desktop.
[javascript] Which fields are filled or empty in my form?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map_which_fields_are_filled_or_not = function (form_id) { | |
/* for each field on form, recognize if it's filled or not. | |
Returns: | |
- { | |
"field_a": true, // filled | |
"field_b": false // empty (not filled) | |
} | |
*/ | |
var fields = {}; | |
$('#'+form_id).find(':input').filter(':visible').each(function() { | |
if (!this.name) { | |
return; | |
} | |
if ((this.type === 'checkbox') || (this.type === 'radio')) { | |
if (!fields[this.name]) { | |
fields[this.name] = $("#"+this.id).prop('checked'); | |
} | |
} else { | |
fields[this.name] = ($("#"+this.id).val().length > 0); | |
} | |
}); | |
return fields; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment