Check if inputs form are empty jQuery
javascript, jquery, symfony, twig
Solution
var empty = true;
$('input[type="text"]').each(function() {
if ($(this).val() != "") {
empty = false;
return false;
}
});
This should look all the input and set the empty var to false, if at least one is not empty.
EDIT:
To match the OP edit request, this can be used to filter input based on name substring.
`$('input[name*="denominationcomune_"]').each(...`
Problem
How can I check in jQuery if inputs with name denominationcomune_{{loop.index}} and denominationcomune_{{loop.index}} are empty not all inputs ? I have a twig like this: ``` <form action="" method="post"> {% for mat in mat_temp_array %} <input type="text" name="nomentite_{{loop.index}}"/> <input type="text" name="denominationcomune_{{loop.index}}" value="{{ mat.denominationcommun }}"/> <input type="text" name="denominationcomerce_{{loop.index}}" value="{{ mat.denominationcomerce }}"/> {% endfor %} <input type="submit" class="btn" value="save"/> </form> ```