We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Conditionally required fields

Development and Programming

infcampus's avatar
infcampus
3 posts
15 years ago
infcampus's avatar infcampus

I have 1 checkbox and 2 date fields. I need the date fields to be required only if the checkbox is checked. It doesn’t seem to be possible “out of the box”, assuming that is correct, can anyone point me in the right direction how to handle this? Or maybe there is a solution already out that I couldn’t find? I considered a hook on publish page to add the validation, but I think I would need to make these all custom fields in order to properly identify them. Or could I do custom checkbox and date fields with the javascript added and skip the hook? (But that would be client side validation which is useless.) Not familiar enough with EE to know what is the best direction to go here.

       
Emily Heath's avatar
Emily Heath
197 posts
14 years ago
Emily Heath's avatar Emily Heath

I put the same question to my EE meetup peeps after no one responded to my similar question here http://ellislab.com/forums/viewthread/194025/ and have had some other ideas of my own since:

(some don’t actually validate, but they allow for determining within the template which date field to be used)

  • make an accessory with jquery to happen on validation (browser intensive whereas other solutions are server intensive)*
  • matrix - 3 fields: 1 = checkbox, 2 = date a, 3 = date b
  • pill field / radio button field could be used to get user to decide which of 2 fields should be shown in template.
  • Use this plugin to hide the date field you don’t want to be completed depending on whether checkbox is checked or not http://devot-ee.com/search/tags/tag/show_hide_fields/

  • why would client side validation be useless?

None of these are perfect. I’m still looking - would love to hear if anyone else has solved this. I wish I knew how to make an accessory to do the jquery validation - maybe time to learn…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.