Custom Form: Using JS to change 'required' status


(M L Sanders) #1

Hi
I've got a form text input which is required: let's say 'Provide Zip Code'.

However, business logic says that if users choose an option that says 'No Zip Code available', then 'Provide Zip Code' should no longer appear.



No problem: easy to use JavaScript to make 'Provide Zip Code' appear/disappear based on the 'No Zip Code available' option: but I'd also like to hook into the Squiz 'required' system, so that any error generated is 'in sync' with other possible error messages.



Can anyone think of a way i might achieve this?



And quick supplementary: does Squiz have no default visual signposting of a 'required' widget on a custom form?



thanks



mark


(Robin Shi) #2

Hi Mark,


Custom form doesn't support conditional questions. I would do the following work-around.

[list=1]

  • Create the question for "Zip Code" as text field, set it required. The error message will read "Please enter your zip code or type 'No Zip code avaivable'", this is for the server validation.[]Turn off client side validation so no validation JS is generated in the front end.[]In Page content, insert JS to create a radio button with the label "No Zip Code available". When the user clicks on the radio button, JS adds the value of string "No Zip code avaivable" into "Zip Code" text field.:slight_smile:



    Robin