Conditionally Render field Required Based on another field Value

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I know this topic has been brought up in previous posts, but I believe my situation is a bit unique, and others may have run into this:

I have a button to "Create a Contact", which shows a pop-up. I want the "state" field to be required only if the "country" = United States". The problem arises where, after the user fills in the country, the model is not re-queried, and therefore the conditional rendering conditions aren't applied.

I know a work-around would be to create a wizard, have them fill in the country, and then the next step re-queries see if the state is required or not, but I'd like to avoid that.

Any ideas?
Photo of Ben Knecht

Ben Knecht

  • 946 Points 500 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 56,366 Points 50k badge 2x thumb
Official Response
My recommendation is this: add the Field that you want to be "Conditionally Required" to your Field Editor, TWICE. Setup both fields exactly the same, but have one be Required, one NOT be required. Then add Rendering Conditions to each so that the "Required" version of the field only shows up when you want it to, otherwise the "non-required" version of the field shows up.

So you want "State" to be required, but only if Country has specific values. So add the State field to your Field Editor TWICE.
First State field -- mark as REQUIRED: Conditionally Render this field so that it only appears if Country = "US"
2nd State field -- Do NOT mark as Required: Conditionally Render this field so that it only appears if Country != "US"