1
Hello! I am using Modelform from Django 2.2, and I need to leave the dynamic form. The "Number of installments" field should only appear when the Payment Method is credit.
At first I tried to do with JS:
function exibir_ocultar(){
var valor = $("#id_metodo_de_pagamento").val();
if(valor == 'credito'){
$("#id_quantidade_de_parcelas").show();
} else {
$("#id_quantidade_de_parcelas").hide();
} };
I came across the problem of not being able to edit select to call the JS function, since Django itself generates the form. Follow the code used to generate the form:
{% bootstrap_messages %}
<form action="{% url 'cadastro' %}" method="POST" class="form" autocomplete="off" >
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" href="{% url 'index' %}" class= "btn btn-success">Salvar </button>
<button type="submit" href="{% url 'index' %}" name="exit" value="True" class= "btn btn-dark">Salvar e fechar </button>
{% endbuttons %}
</form>
What is the best way to accomplish this action?