Make sure showing/hiding works on page load

Fixes #53
This commit is contained in:
Carl van Tonder 2018-04-04 13:12:00 -04:00
parent 6add9a10aa
commit f19f501684

View File

@ -34,16 +34,6 @@
<!-- Conditional logic for hiding and un-hiding fields. --> <!-- Conditional logic for hiding and un-hiding fields. -->
<script type="text/javascript"> <script type="text/javascript">
// Button classes for tab navigation
$('.btnNext').click(function(){
$('.nav-tabs > .active').next('li').find('a').trigger('click');
});
$('.btnPrevious').click(function(){
$('.nav-tabs > .active').prev('li').find('a').trigger('click');
});
// Here we define the fields we need to conditionally toggle. // Here we define the fields we need to conditionally toggle.
// TODO: Move this knowledge out of the template // TODO: Move this knowledge out of the template
var conditionalFields = [{ var conditionalFields = [{
@ -97,9 +87,6 @@
"condition": ["N"] "condition": ["N"]
}]; }];
// Here we define the checkboxes that we need to use to // Here we define the checkboxes that we need to use to
// conditionally toggle fields - they use slightly different // conditionally toggle fields - they use slightly different
// logic as they rely on the 'checked' attribute rather than value. // logic as they rely on the 'checked' attribute rather than value.
@ -165,7 +152,29 @@
return array.indexOf(value) > -1; return array.indexOf(value) > -1;
} }
$(document).ready(function(){
// Button classes for tab navigation
$('.btnNext').click(function(){
$('.nav-tabs > .active').next('li').find('a').trigger('click');
});
$('.btnPrevious').click(function(){
$('.nav-tabs > .active').prev('li').find('a').trigger('click');
});
$('form').attr('novalidate', 'novalidate');
conditionalFields.forEach(addConditionalField); conditionalFields.forEach(addConditionalField);
conditionalCheckboxes.forEach(addConditionalCheckbox); conditionalCheckboxes.forEach(addConditionalCheckbox);
conditionalFields.forEach(function(item){
$(item.field).change();
});
conditionalCheckboxes.forEach(function(item){
$(item.checkbox).change();
});
});
</script> </script>
{% endblock %} {% endblock %}