Memberscripts by Memberstack

#125 - Checkbox Toggle Required On Form Fields

Set form fields to required or not based on the value of a checkbox.

Set required if checkbox is checked

If this checkbox is checked, the name and email field will become required. If not, they will be optional.

Mandatory attributes:
 ms-code-req-if-checked (the checkbox that changes the required state), ms-code-req-input (the input - or inputs - that will be required if the checkbox is checked).

Optional attributes: ms-code-req-label (Will hide when the input is not set to required)

Use the attribute values to group sets together.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Remove required if checkbox is checked

If this checkbox is checked, the name and email field will become optional. If not, they will be required.

Mandatory attributes:
 ms-code-req-if-unchecked (the checkbox that changes the required state), ms-code-req-input (the input - or inputs - that will be required if the checkbox is unchecked).

Optional attributes: ms-code-req-label (Will hide when the input is not set to required)

Use the attribute values to group sets together.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Set disabled if not required

This can be used in combination with the previous 2 examples - but, this attribute added to the checkbox will make it so that when the fields are not required, they are also set to 80% opacity and have pointer events set to none.

Mandatory attributes:
 ms-code-disable-if-not-req (add this to the checkbox in combination with the previous sets of attributes).

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.