Conditional required fields

This topic contains 2 replies, has 2 voices, and was last updated by  Stephen Harris 10 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9497

    Hi Stephen
    Is there any way to change a fields ‘required’ attribute with Javascript? I’ve added a couple of fields that are hidden at page load and only appear once a certain condition is met. I’d like to make them required only if they are shown. Example:

    We have an event that is normally attended by adults with children. However children can attend on their own if they have parental consent. So I’ve added a bit of jQuery that shown a consent tick box and parent name field if child tickets > 0 and parent tickets == 0. I want these fields to become required only if that condition is met.

    Is there any way to achieve this?

    Cheers
    Stuart

    Stuart Farish
    #9502

    You could listen for when the user makes a ticket selection and then add/remove the field. However, if it’s ‘required’ in the form customiser then the server-side checks will reject the booking unless its has been filled in. You could around this by not making it a required field and then adding additional checks when the server validates the booking.

    (Here’s an example of additional validation checks – in particular the second section).

    Stephen Harris
    #9503

    I should add that 1.6 is bringing it with a checkout (javascript) API. The idea is that you could listen for a change in the checkout ‘basket’ and act accordingly. In fact its already available, but being improved. The VAT and Discount Codes extension to calculate the appropriate VAT/discount and add a row to the booking cost table.

    Stephen Harris
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.