I have a Django app with a form (id = form_unblind_form) with valid button (id = unblind_edit).
I want to display a modal with informations from database using ajax query.
And it works but there is an anormal behavior.
The problem is that as modal.sow() is called in success ajax return, modal is displayed even if form is not valid and that is not a correct behavior
But I can find the right algo to do that
thanks for help
//1. first form submission is prevented until OK button on modal is clicked
$("#form_unblind_edit").submit(function (event) {
if (!prevent_edit) {
event.preventDefault();
}
});
//2. I query database to recovered information for modal
$("#unblind_edit").on("click", function (event) {
var csrftoken = getCookie('csrftoken');
var patient = $("#id_pat").val();
var treatment = $("#id_unb_num").val();
$.ajax({
type: "POST",
url: '/unblind/already_unblind/',
data: {
csrfmiddlewaretoken: csrftoken,
'patient': patient,
'treatment': treatment
},
dataType: 'html',
success: function (data) {
$("#popup").html(data);
$('#unblindconfirm').modal('show'); //<- PROBLEM HERE as modal is always displayed
},
});
});
//3. If user click on OK button, form is finally submitted
$("body")
.on('click', '#edit_button_OK', function (event) {
$('#edit_button_OK').attr("disabled", "disabled");
prevent_edit = true;
$("#form_unblind_edit").submit();
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…