Javascript hack to make it more clear that postcode is mandatory

On the two pages that display the profile form, add some javascript to
flag the postcode as required whenever the Country is AU
This commit is contained in:
James Polley 2017-10-01 18:39:20 +11:00
parent 38a99f7ae5
commit 348e1c5c82
2 changed files with 31 additions and 4 deletions

View file

@ -8,6 +8,21 @@
{% for section in sections %} {% for section in sections %}
{{ section.form.media.js }} {{ section.form.media.js }}
{% endfor %} {% endfor %}
<script type="text/javascript">
postcode_label = $("label[for='id_profile-state']");
postcode_help = $("#id_profile-state + p");
$('#id_profile-country').change(function () {
if ($(this).val() == 'AU' ) {
postcode_label.addClass('label-required');
postcode_help.show();
} else {
postcode_label.removeClass('label-required');
postcode_help.hide();
} });
$("#id_profile-country").change();
</script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}

View file

@ -8,13 +8,25 @@
{% endblock %} {% endblock %}
{% block scripts_extra %} {% block scripts_extra %}
{{ form.media.js }} {{ form.media.js }}
<script type="text/javascript"> <script type="text/javascript">
</script> postcode_label = $("label[for='id_profile-state']");
postcode_help = $("#id_profile-state + p");
$('#id_profile-country').change(function () {
if ($(this).val() == 'AU' ) {
postcode_label.addClass('label-required');
postcode_help.show();
} else {
postcode_label.removeClass('label-required');
postcode_help.hide();
} });
$("#id_profile-country").change();
</script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
THIS IS THE FORM
<form class="form-horizontal" method="post" action=""> <form class="form-horizontal" method="post" action="">
{% csrf_token %} {% csrf_token %}