I want to validate my form in a modal window? and tried in several ways I validated the form but when I accept it does not return me to the modal window and the information is sent causing a django error, I want to know if field can be validated by field and that I return to the modal window with the error.
This is my form in the modal window.
<div class="modal fade" id="agregarboncheo" role="dialog" data-backdrop="static">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="cerrarmodal" data-dismiss="modal"><i class="fa fa-close"></i></button>
<h4> <span><i class="fa fa-plus"></i></span>Nuevo Boncheo</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<form class="formatolinea" method="post" name="nregistro">
{% csrf_token %}
<label>Bonchador</label>
<select required="" name="boncheador">
<option>Nombre del bonchador</option>
{% for obj in bonchador %}
<option>{{obj.nombre}} {{obj.apellidos}}</option>
{% endfor %}
</select>
<label>Variedad</label>
<select required="" name="variedad">
<option>Seleccione la variedad</option>
<option>freedom</option>
<option>vendela</option>
</select>
<label>Bonches</label>
<input type="number" name="bonches" placeholder="Cantidad de bonches">
<label>Unidades</label>
<select id="unidades" name="unidades" onChange="mostrarl(this.value);">
<option>Seleccione las unidades</option>
<option value="12">12</option>
<option value="20">20</option>
<option value="25">25</option>
</select>
<label>Grado</label>
<select required="" name="grado">
<option>Seleccione el grado</option>
<option>40</option>
<option>50</option>
<option>60</option>
<option>70</option>
</select>
<label>Lámina</label>
<select required="" name="lamina">
<option>Seleccione la lamina</option>
<optgroup label="Lamina" id="lamina1" style='display: none;'>
<option>Benchmark</option>
<option>Golden</option>
<option>Microcorrugada</option>
</optgroup>
<optgroup label="Lamina" id="lamina2" style='display: none;'>
<option>Pet Transparante con papel</option>
<option>Transparante</option>
</optgroup>
</select>
<button class="guardar" type="submit" onclick="mensajes();"> <i class="fa fa-save"></i> Guardar</button>
<button class="cancelar" type="reset" data-dismiss="modal"> <i class="fa fa-close"></i> Cancelar</button>
</form>
</div>
<!-- /.containerfluid -->
</div>
<!-- /.modalbody -->
<div class="modal-footer">
</div>
<!-- /.modalfooter -->
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->