Field validation that depends on the value of another field

Antony V asked on November 14, 2017 20:17

In a custom module, I have a field that I want to make required, but only if another field on the form has a certain value. The field that I want validated appears only when the user selects an appropriate option from the other field, which is represented visually by a dropdown. That part works, but I also want to add validation. Is there any way to do that in the UI? I know, as a workaround, I can add an event hook, but I'd like to keep this logic all in one place, i.e. in the module>class>form editor.

Recent Answers


Matt Nield answered on November 15, 2017 09:00 (last edited on November 15, 2017 09:03)

If you’re using the Visibility condition, then you should be able to just mark the field as required. Kentico will not render the control of the Visibility condition is not met.

There is a good article by Jan about how to work with depending fields which might be worth reading through.

1 votesVote for this answer Mark as a Correct answer

Antony V answered on November 23, 2017 22:22 (last edited on October 2, 2018 19:36)

That may work if I set a default value. From what I've seen, fields that are marked as required are set to not allow nulls in the DB, so without a default value, an insert would fail regardless of the visibility condition.

0 votesVote for this answer Mark as a Correct answer

Kàren Vaganyan answered on October 2, 2018 19:33

Did you ever find an answer to this?

0 votesVote for this answer Mark as a Correct answer

Antony V answered on October 2, 2018 19:41

@Kàren, No, I don't think I pursued it further.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.