I have a form that is rather long, therefore I want to split it into sections.
I am doing this with jQuery conditional fields in forms.
The first 5 fields appear, once the user enters input for the fields and then they click on a checkbox, the filled fields are then hidden and the next 5 questions are unhidden, and this is repeated every 5 questions.
I was wondering if there is a way to show the fields again that were hidden after clicking the checkbox, in case the user unchecks the box in an attempt to view the previous 5 questions again. Because what happens now when the box is unchecked is that it hides the fields that it revealed but doesn't show the previous 5 fields unless you uncheck and recheck the box.
Also, I am basically repeating the following code from the book:
{{extend 'layout.html'}}
{{=form}}
<script>
jQuery(document).ready(function(){
if(jQuery('#taxpayer_married').prop('checked'))
jQuery('#taxpayer_spouse_name__row').show();
else jQuery('#taxpayer_spouse_name__row').hide();
jQuery('#taxpayer_married').change(function(){
if(jQuery('#taxpayer_married').prop('checked'))
jQuery('#taxpayer_spouse_name__row').show();
else jQuery('#taxpayer_spouse_name__row').hide();});
});
</script>
I have 3 seperate sections of the form, each section has it's own script, showing and hiding 5 form fields within each. I don't understand jQuery all that well, is there a way to make it less repetitive? I'm over 160 lines of code for just showing and hiding fields, I'm hoping there is a better way.