I am refactoring a large old web application that has several complex forms.
These forms use javascript to show or hide fields based on other fields entered. For example, a check mark for "second address" shows a set of other input fields.
The current check for this consists of many deeply nested if statements. Similar to:
if(checkboxTicked) {
haveMandatoryAddressFieldsBeenEntered();
if(addressHasbeenFilledIn) {
validateAddress()
}
}
Now imagine this example with a much deeper nesting!
My question is: is there a good example or best practice with which I can reorganize this?
For reference, I use Spring MVC - but I assume this applies to several technologies.