What is the template for deeply nested web form validation?

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.

+3
1

MVC . , .

+1

Source: https://habr.com/ru/post/1711698/


All Articles