[SalesForce] Best practice for JQuery to hide/show a section with required fields

I'm building a wizard where I've a page splitted in some sections. One of them is shown/hidden based on the value selected for a picklist of another section, by using JQuery. But, the conditional section contains some required fields. So, even if the section remains hidden, when I try to save I get the error because of the null field that shoul be required. (and I can see the error on the field If I make the conditional section appear). This troubles do not exist, instead, when exploiting the rendered attribute(that I cannot use because I need something on the fly).

Any suggestions?

Best Answer

I'm not sure whether the field needs to be required when it's invisible? If not, simply use a validation rule to check whether the picklist that reveals the hidden section has a value. Then you can validate whether the required field has a value.

An alternative solution would be to use jQuery to:

  • check whether any of the fields in the hidden section(s) contain any input and show the section if it does.
  • find all elements with class "errorMsg", check whether the error message inside matches with that of a hidden field, show the related section if it does.

This way your field can stay required. Keep in mind that if you want the picklist that was meant to reveal this section to be filled in too, you'll need to make it required.