Hello,
in the end i have used another way which seems to work fine in the modal theme.
Now the problem comes with displaying the fields, I am trying several ways but there is no way.
I imagine that in the views.py file I have something wrong.
class CrearReclamacion(CreateView):
model = Rec
form_class = RecForm
template_name = 'reclamaciones/crear_reclamacion.html'
success_url = reverse_lazy('Reclamaciones')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['formulario'] = RecForm()
return context
html page where the modal is displayed:
<div class="modal fade" id="myModalClient" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<form action="" method="POST" enctype="multipart/form-data" class="form-control">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Modal title</h1>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{% for field in formulario.visible_fields %}
<div class="form-group">
<label for="email">{{ field.label }}:</label>
{{ field|add_class:'form-control'|attr:'autocomplete:off' }}
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</form>
</div>
for something I am not understanding or putting incorrectly.
In views.py I have a CrearReclamacion class where it goes to a form crear_reclamacion.html. This part is the one I want to modify so that it goes to the modal.
I also sample the .js file
var table = $(function() {
$('#data').DataTable({
responsive: true,
autoWidth: false,
destroy: true,
deferRender: true,
ajax: {
url: window.location.pathname,
type: 'POST',
data: {
'action': 'searchdata'
},
dataSrc: ""
},
columns: [
{"data": "fecha_reclamacion"},
{"data": "num_reclamacion"},
{"data": "num_cliente"},
{"data": "empresa"},
{"data": "tipo"},
{"data": "atiende"},
{"data": "delegacion_departamento"},
],
columnDefs: [
{
targets: [-1],
class: 'text-center',
orderable: false,
render: function (data, type, row) {
var buttons = '<a href="#" class="btn btn-warning btn-xs btn-flat"><i class="fas fa-edit"></i></a> ';
buttons += '<a href="#" type="button" class="btn btn-danger btn-xs btn-flat"><i class="fas fa-trash-alt"></i></a>';
return buttons;
}
},
],
initComplete: function (settings, json) {
}
});
$("#myModalClient").modal("show");
For now it only makes it show the modal when loading the page, for now I only want to load the fields of my table inside the modal, that’s what I don’t get.
thank you