-
I have an admin view that has fields like this: Field A - radio (yes/no) Field B - radio (yes/no) None of these fields are 'required'. HOWEVER, IF the user sets Field A to YES, then Field A1, A2, A3 all need to become required. This all needs to be done within the browser (i.e. JS code) on the front-end (although should also work on the admin). I have NO IDEA how to go about this. Can anyone point me in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Hi Chris
I guess I would write some JS code for the ONCHANGE functionality of FIELDA which changes the other FIELD’s attributes to required/not required…
And the same for each field, or call a common function from each onchange which checks the values/attributes of the other fields and changes the attributes.
Franz
From: Chris Paschen ***@***.***>
Sent: Friday, 03 December 2021 05:52
To: vdm-io/Joomla-Component-Builder ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [vdm-io/Joomla-Component-Builder] make field required on condition of other field (Discussion #835)
I have an admin view that has fields like this:
Field A - radio (yes/no)
Field A1 - custom, multi-select
Field A2 - custom, multi-select
Field A3 - custom, multi-select
Field B - radio (yes/no)
Field B1 - custom, multi-select
Field B2 - custom, multi-select
Field B3 - custom, multi-select
None of these fields are 'required'.
HOWEVER, IF the user sets Field A to YES, then Field A1, A2, A3 all need to become required.
Similar if Field B is set to YES, then Fields B1, B2, B3 all need to become required.
And if they set either of these fields back to NO, then the respective 1,2,3 fields need to be re-set to NOT required.
This all needs to be done within the browser (i.e. JS code) on the front-end (although should also work on the admin).
I have NO IDEA how to go about this.
Can anyone point me in the right direction?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#835> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALIFNZ7W4HMOCIS5B6CSCDTUPA5FTANCNFSM5JIXTXJA> .
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub> . <https://github.com/notifications/beacon/ALIFNZ3DA5YSQCMXTYOX3UTUPA5FTA5CNFSM5JIXTXJKYY3PNVWWK3TUL52HS4DFVJCGS43DOVZXG2LPN2VGG33NNVSW45C7NFSM4ABYYRCA.gif>
|
Beta Was this translation helpful? Give feedback.
-
I've used this code below for a similar scenario.
|
Beta Was this translation helpful? Give feedback.
-
Thanks to everyone that helped out. Using snippets from several responses (and a few others online I found), here's the final solution that worked, at least for my usecase.
NOTE: In addition to setting the fields required, I also manually added/removed the "*" required indicator. Hope that helps someone else running into this. BTW ... this needs to be added to the javascript_view_footer area. It can not be added to the external .js file for the view. Thanks for all the help. |
Beta Was this translation helpful? Give feedback.
Thanks to everyone that helped out. Using snippets from several responses (and a few others online I found), here's the final solution that worked, at least for my usecase.
[This code was placed in the 'admin_view.javascript_view_footer' area.]