Conditional Form fields

Deann Graham asked on January 21, 2016 19:30

I need to make a form field require, but only if they have selected an option from a select field. If the user selects other in a select option the field more information becomes required. Is that Macro conditions?

Correct Answer

Bryan Soltis answered on January 21, 2016 22:14

Ah I understand now. The Required box is what tells the DB it's a required field, so one solution could have the field marked as Required, but set it as Not Enabled using the example I sent. If they don't ever enter a value, you could set the default to some blank space or something. This isn't a great solution because you potentially have erroneous data in the DB for your records.

I looked into making a Validation Rule for the field (trying to make it look at the "other" filed's value), but it doesn't seem to know how to find those values.

Only options I can think of are to:

  • Define a custom macro that your Validation rule could look at. Still, this may not work if it never executes the validation if the field is empty.

  • Write some JS to validate the values (looking at the field values) and injecting that into the form layout. This is probably the route I would take if the Required option above didn't work.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Bryan Soltis answered on January 21, 2016 20:46

I think you should be abel to sue the "Has Depending Fields" for the field to determine if it's visible.

Here's a good article to show how to make a field visible based on another selection.


1 votesVote for this answer Mark as a Correct answer

Deann Graham answered on January 21, 2016 20:57

What if it is not a matter of visibility? They want the field there always. Just want it required if they select an option.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on January 22, 2016 08:28


as a part of validation you can check a value of another field, so the text box won't be required, but some other required field check its value if its not empty only when some selection is made.

Similar approach is described in last example in this article:

Best regards,
Jan Hermann

1 votesVote for this answer Mark as a Correct answer

Deann Graham answered on May 25, 2016 17:25 (last edited on May 25, 2016 17:30)

If you don't mind the form having to go back to the server then Bryan's solution is the best. Kentico has the ability to make conditions in the fields with some k#. All through the portal. No need for getting into custom code. Easy. Some articles may note an older version, but it is the same all the way to 9. Jan's article suggestion is more expanded. However. If you have the form in an Accordion this will make the whole thing flash and reopen. Cause.. it is a server side request and things like accordions are client side. So, Bryan is correct again. JavaScript would be required for validation and making the field visible. If it is Client-Side problem it will probably be a Client-side solution. My solution ended up requiring the JS to add and remove classes to make the field visible and passing values to the field to allow for validation. Again that might cause problems down the line because you are injecting a fake value. Could dirty the Data.. but at this time for us this was acceptable. Many thanks to Bryan Soltis and Jan Hermann.

0 votesVote for this answer Mark as a Correct answer

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