We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Hi,

    I have a form which has some hidden fields, these are displayed if a user answers ones of the 'in view' fields with a relevant answer. I am using jQuery to show/hide the optional fields based on the answer to the 'conditional' field - I need all form fields to be validated - but cant use the standard validation as it will look at the hidden fields and validate them even if they are hidden and not needed to be validated... e.g. I only need them validated if they are in view...

    Any ideas?

    Could rather than hide them in jQuery - inject them / delete them I guess... but prefer to keep it simpler and show/hide them and use a custom validator if it will work?

    Any thoughts?

    Cheers


    dubbs.

    This question has been answered by dubbs. See the first response.

      • 8168
      • 1,118 Posts
      Any ideas anyone?
      • discuss.answer
        • 8168
        • 1,118 Posts
        OK ended up doing it a fairly unique way... for those who are interested...

        I added a new option element to all the optional option fields with the value "notrelevant" - I then in jQuery, when i changed the view status of these fields to be in view, I removed that "notrelevant" option from the select field. So, with formit validate:required set on all fields it now works, as each optional select field starts with the value "notrelevant" so passes the required validation test, and when the user opts to view the optional select form fields, jquery removes the unwanted "notrelevant" option for us...