Skip to Content Skip to Menu

🌟 CB Editor Assistant 1.0.0 is here! Discover our new AI Joomla Plugin that wrote its story! (and this banner!)
Start at just $12.50/month* or 💸 save 30% with our 🛍️ Black Friday Intro Offer for your subscription's lifetime
🎉 Black Friday sale is here! Great savings on professional and developer memberships! Get 25% off now with code BLACK-FRIDAY-2024!

Auto-Check a Checkbox Field?

  • bascherz
  • bascherz
  • OFFLINE
  • Posts: 228
  • Thanks: 29
  • Karma: 11
6 years 7 months ago - 6 years 7 months ago #303400 by bascherz
Auto-Check a Checkbox Field? was created by bascherz
So far CB Core Ajax is adding awesomeness to my site. For instance, I can make a Checkbox (Single) field appear based on some other field being Not Empty using Integrations/CB Conditional. But what if I also want to, when that checkbox field appears, make it be checked by default? I thought CB Auto Actions would be the way to go, but what I really want is to just have the checkbox checked by default so that when the profile is saved all registered plugins execute as usual. It seems to me there must be a way to do this, but I can't figure it out. Could use a bit of help with this simple task.

Thanks in advance.

EDIT: As is my usual, I kept trying different things and I did get something to work. I was trying to use the onAfterUserUpdate trigger with CB Auto Actions, when in fact the correct one is onBeforeUserUpdate. This does work even though the checkbox is not visibly checked before the Update button is clicked. If the box is checked manually, it doesn't affect how the auto-action works. So I believe this solution is acceptable even though having a check in that box would be ideal.

Bruce S - Vienna, VA
Last edit: 6 years 7 months ago by bascherz.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48560
  • Thanks: 8292
  • Karma: 1445
6 years 7 months ago #303414 by krileon
Replied by krileon on topic Auto-Check a Checkbox Field?
When a field is hidden by CB Conditional its value is reset. So the checkbox is reset to unchecked. There is no option to specify a default value for the reset (there are no plans at this time to implement this) and there's no option in CB it self to specify a default other than for new registrations (plans to expand this to existing users sometime in the future).

You can hook into the jQuery of CB Conditional and extend it with additional behavior using CB Auto Actions and its Code action on the onBeforeUserProfileEditDisplay trigger if you're familiar with jQuery. The cbcondition.match.true event in your case would be used and is bound to the element the condition is configured on. Example as follows.

Code:
$( '#cbfr_FIELD_ID_HERE' ).on( 'cbcondition.match.true', function( e, condition ) { // CODE HERE });

There's also cbcondition.match.false if you need to match against the condition not matching.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum