I have a form that was auto generated by my backend. I try to serialize array withouth success. How can I find the error ?
I have tried to select my form with jquery and the form is found. All the inputs have name.
Here is the HTML
<div class="modal fade show" tabindex="0" role="dialog" id="modals-validation-tacite" data-idsource="validation-tacite" aria-modal="true" data-vivaldi-spatnav-clickable="1" style="display: block; padding-right: 17px;">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Validation de la Tacite</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="#" method="POST" role="form">
<div class="container-fluid">
<input type="hidden" name="csrf" id="csrf" value="3573ee07287bcb2c29e124f673587e3712e67880dcf2fe76ec0b775132960b50-075d2c347340cd4fc527be7cdc2b5ee89224e749d3f995171d7bb112cdb57ab8" disabled="">
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="nb-tacite" id="nb-tacite-label" class="form-control-label">Nombre de tacites <abbr class="required" title="champ obligatoire">*</abbr> :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<input type="number" name="nb-tacite" aria-label="Nombre de tacites" id="nb-tacite" class="form-control" value="" disabled="">
</div>
</div>
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="duree-tacite" id="duree-tacite-label" class="form-control-label">Durée de la tacite (en années) <abbr class="required" title="champ obligatoire">*</abbr> :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<input type="number" name="duree-tacite" aria-label="Durée de la tacite (en années)" id="duree-tacite" class="form-control" value="" disabled="">
</div>
</div>
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="duree-preavis-tacite" id="duree-preavis-tacite-label" class="form-control-label">Durée de préavis (en mois) <abbr class="required" title="champ obligatoire">*</abbr> :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<input type="number" name="duree-preavis-tacite" aria-label="Durée de préavis (en mois)" id="duree-preavis-tacite" class="form-control" value="" disabled="">
</div>
</div>
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="date-fin-tacite" id="date-fin-tacite-label" class="form-control-label">Date de fin de tacite <abbr class="required" title="champ obligatoire">*</abbr> :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<input type="date" name="date-fin-tacite" aria-label="Date de fin de tacite" id="date-fin-tacite" class="form-control" value="" disabled="">
</div>
</div>
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="date-maj-tacite" id="date-maj-tacite-label" class="form-control-label">Date de mise à jour dans GID <abbr class="required" title="champ obligatoire">*</abbr> :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<input type="date" name="date-maj-tacite" aria-label="Date de mise à jour dans GID" id="date-maj-tacite" class="form-control" value="" disabled="">
</div>
</div>
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="commentaire" id="commentaire-label" class="form-control-label">Commentaire :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<textarea name="commentaire" aria-label="Commentaire" id="commentaire" class="form-control" disabled=""></textarea>
</div>
</div>
<div class="form-group row">
<div class=" col-12 col-md-6 text-sm-left text-md-right ">
<label for="tacite_flag" id="tacite_flag-label" class="form-control-label">GID est à jour <abbr class="required" title="champ obligatoire">*</abbr> :</label>
</div>
<div class=" mb-2 mb-md-0 col-12 col-md-6 ">
<div class="form-check">
<div class="form-check-label"> <input type="hidden" name="tacite_flag" value="0" disabled=""><input type="checkbox" name="tacite_flag" aria-label="GID est à jour" id="tacite_flag" aria-labelledby="tacite_flag-label" class="form-check-input" value="1" disabled=""></div>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" data-idsource="validation-tacite">Fermer</button>
<button type="button" class="btn btn-primary modal-send" data-idsource="validation-tacite" data-vivaldi-spatnav-clickable="1" disabled="">Sauvegarder</button>
</div>
</div>
</div>
</div>
And the jquery :
var formData = $('modals-validation-tacite form').serializeArray()
I should be getting an array with all key values but I am getting empty array from this.
modals-validation-tacite, correct? Your jQuery should the likewise be informed that it is targeting an id in the selector. I.e.var formData = $('#modals-validation-tacite').serializeArray();. Also note thatserializeArray()converts your input data to JSON format.