dimanche 29 mars 2015

Django OnClick Submit Button not showing confirmation pop-up

I have a form in which I wanted to have the Submit button have a pop-up to ask the user if they are sure they want to submit the form with the options 'OK' and 'cancel'. This seemed to work on all of my other forms but this one is not. Instead of showing the pop-up and asking the user for confirmation, it just submits.


Wondering if this might be because of a clash with the JS or another part of the logic in the form...


Code:



{% extends "prod/page_base.html" %}

{% load dajaxice_templatetags %}
{% load static %}

{% block title %}{{ edit_add }} product configuration{% endblock %}

{% block dajax %}
{% dajaxice_js_import %}
<script src="{% static 'dajax/jquery.dajax.core.js' %}"></script>
{% endblock %}

{% block script %}
<script src="http://ift.tt/183v7Lz"></script>
<script>
$(document).ready(function(){
if ($("#id_line").val() != "group1" && $("#id_line").val() != "group2") {
$("#group_fields").hide();
}
$("#id_line").click(function() {
if ($("#id_line").val() != "group1" && $("#id_line").val() != "group2") {
$("#group_fields").hide();
}
else {
$("#group_fields").show();
}
});
});
</script>
{{ form.media }}
{% endblock %}

{% block pagetitle %}{{ edit_add }} Product Configuration{% endblock %}

{% block page_content %}

{% if form.errors or formset.errors %}
<p class='error_note'><strong>Please correct the error{{ form.errors|pluralize }} below.</strong></p>
{% endif %}

<form class="edit" method="post" enctype="multipart/form-data">{% csrf_token %}
{{ form.non_field_errors }}
<p>
{{ form.name.errors }}
<label for="id_name">Product Name:</label>
{{ form.name }}
</p>
<p>
{{ form.line.errors }}
<label for="id_line">Product Line:</label>
{{ form.line }}
</p>
<div id="group_fields">
<p>
{{ form.type.errors }}
<label for="id_type">Type:</label>
{{ form.type }}
</p>
</div>
<p>
{{ form.reason_for_change.errors }}
<label for="id_reason_for_change">Reason for change (mandatory):</label>
{{ form.reason_for_change }}
</p>
<input class="button" type="Submit" value="Commit changes" onclick="return confirm('Submit changes?')">
</form>

{% endblock %}

Aucun commentaire:

Enregistrer un commentaire