I'm refactoring a large legacy web application that has some complicated forms.
These forms use javascript to display or hide fields on the basis of other entered fields. E.g ticking a checkbox for "second address" reveals a set of other fields to enter.
The current validation for this consists of lots of deeply nested if statements. Similar to:
if(checkboxTicked) {
haveMandatoryAddressFieldsBeenEntered();
if(addressHasbeenFilledIn) {
validateAddress()
}
}
Now imagine this example with much deeper nesting!
My question is - is there a nice pattern or best practice that I can refactor this with?
For reference I'm using Spring MVC - but I guess this would apply across multiple technologies.