Change value of a radio group after reading data

  • MikeDiggins
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 48
  • Thank you received: 0

MikeDiggins created the topic: Change value of a radio group after reading data

I have a two-option radio group to show if a person is local or from overseas; the default is "local". The value of the group affects the display of information about the person using visibility rules on form sections. If I read an overseas person's record from the database, how do I change the radio group option from the default while populating the form, please? I feel I'm missing something simple, and I can see how to turn the sections on and off using bfToggleFields - but not how to change the radio group option using code. I have a default visibility rule defined.
#232153
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Change value of a radio group after reading data

Hello,

I'm not sure what you want to achieve or, to be concrete, when exactly should the radio group value be changed. Can you please explain a bit more?

You wrote "how do I change the radio group option from the default while populating the form, please?".

When defining the radio group like this for example:
0;Title1;value1
1;Title2;value2
For the value for which you put 1 before the first semi-colon is the value that will be pre-selected (deault) when filling in the form.

Regards,

Mihaela
#232170
  • MikeDiggins
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 48
  • Thank you received: 0

MikeDiggins replied the topic: Change value of a radio group after reading data

Thanks Mihaela
That could have been clearer, I'm afraid. I understand setting the default on initial load by the "1" as you explained. What I'm not clear about is:
After the initial form load, suppose I enter some sort of key - an email, for example - and ask for the database record with that key. When the record is returned, I populate the form with its data. I need to set the radio group according to the data in the returned record; if that value is not the default, how do I change the radio group option to show that, please?
#232171
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Change value of a radio group after reading data

Ok, now I understand what you want to achieve.

You can set the radio group to wanted value using the Javascript:
jQuery("#ff_elem26776_1").attr('checked', true);
NOTE: In the code you have to replace the ff_elem26776_1 with the correct id of the radio group option that you want to check.
You can get the ID by Inspecting the element.

Other code that would do the same thing is:
opts =  JQuery("[name=\"ff_nm_radiogroupname[]\"]");
for (o = 0; o < opts.length; o++)  { 
   if(opts[o].value == "value2") {
      JQuery("#"+opts[o].id+"").attr("checked", true);  }
 }
NOTE: In this piece of code you would have to replace value2 with the option that you want to check and radiogroupname with the radio group name.

In my opinion it is better to use the first code since it's much simpler.

You wrote "When the record is returned, I populate the form with its data". Implementing this code to select a radio group option depends on how you grab the value from record which is returned.

Regards,

Mihaela
#232191
The following user(s) said Thank You: MikeDiggins
  • MikeDiggins
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 48
  • Thank you received: 0

MikeDiggins replied the topic: Change value of a radio group after reading data

Excellent, thank you - that will do exactly what I need. I thought it would be something like that as I'd seen similar code for reading the group's value, but not for setting it. My knowledge of the JS object model isn't great (yet) but thanks to the Crosstec team, its geting there!
#232222
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Change value of a radio group after reading data

Hello again,

I'm glad that this is what you were looking for.

Great that you are improving your JS skills with us. :)

If you'll have more questions, feel free to ask.

Regards,

Mihaela
#232240
Moderators: ForumSupporttomeperica
Time to create page: 0.070 seconds

New Support System

Dear Customers,

Users with active subscription have support priority which will be dona via ServiceDesk (My Account > Raise a ticket).
FREE Support topics will be answered when AND if there is time.

You can check support guidelines here : here

Regards,
Crosstec Team

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here