TOPIC:

Populating a radiogroup programatically 11 months 4 days ago #237391

  • MarioPuco's Avatar
  • MarioPuco
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 5958
  • Karma: 119
  • Thanks: 554
Hi,

// You can't just overwrite the input element with the data as you would from BreezingForms backend.
// You have to manually change the value and innerHTML of those radio buttons.
// You can use i as the counter for radio group elements, so since your PHP returns an array which has 6 array elements each,
// the strings for the radio group elements are 3, 4, 5 and 6.
// Split them by ';' and use the second element (index = 1) for the innerHTML and the third element (index = 2) for the value.
var rgs = document.querySelectorAll('[name="ff_nm_' + a_name + '[]"]');
rgs.forEach((rg, i) => {
rg.value =
// get the value part of the string 0;text;value, split it by ';' and take the last part
rg.innerHTML = // get the text part of the string
});

Rgds,
Mario

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

Last edit: Post by MarioPuco.

Populating a radiogroup programatically 11 months 4 days ago #237392

  • Topic Author
  • baileynp
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 76
  • Thanks: 1
Hi

Thanks for the reply, but I'm not exactly sure what you mean. :(

Could you possibly give me an example?

Thanks

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

Populating a radiogroup programatically 11 months 4 days ago #237394

  • Topic Author
  • baileynp
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 76
  • Thanks: 1
Hi Mario

Darko suggested I used the following code:
for (x = 0; x < arr.length; x++) {
    // Populate the radiogroups (answers)
    var rgs = document.querySelectorAll('input[name="ff_nm_' + elem_a + '[]"]');
    var ffelem = rgs[0].getAttribute('id');
    rgs.forEach((rg, p) => {
        rg.value = arr[x][2*p + 4];
        jQuery('label[for*="' + ffelem + '"]')[p].html(arr[x][2*p + 3]);
    }); // forEach
} // for x

In this code he used the undefined variable 'p', which I added as:
for (x = 0; x < arr.length; x++) {
    // Populate the radiogroups (answers)
    var rgs = document.querySelectorAll('input[name="ff_nm_' + elem_a + '[]"]');
    var ffelem = rgs[0].getAttribute('id');
    [b]var p = 1;[/b]
    rgs.forEach((rg, p) => {
        rg.value = arr[x][2*p + 4];
        jQuery('label[for*="' + ffelem + '"]')[p].html(arr[x][2*p + 3]);
        [b]p++;[/b]
    }); // forEach
} // for x

Unfortunately, the result is the same - the correct data is returned from the array, but rg.value = arr[x][2*p + 4]; doesn't change any of the radiogroup values, and the jQuery line generates the error:

jQuery('label[for*="'+ffelem+'"]')[p].html is not a function. (In 'jQuery('label[for*="'+ffelem+'"]')[p].html(arr[x][2*p+3])', 'jQuery('label[for*="'+ffelem+'"]')[p].html' is undefined)


Please can you take a look?

Thanks

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

Populating a radiogroup programatically 11 months 2 days ago #237401

  • Topic Author
  • baileynp
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 76
  • Thanks: 1
Update - I've got it working!!! :):)

The code Darko supplied didn't like the line:
jQuery('label[for*="' + ffelem + '"]')[p].html(arr[x][2*p + 3]);

I've got it working with a fudge which is:
for (var i = 0; i < arr.length; i++) {
...
	// Populate the radiogroups (answers)
	var rgs = document.querySelectorAll('input[name="ff_nm_rg_' + section + '_' + arr[i][1] + '[]"]');
	var elem_id = rgs[0].getAttribute('id');
	var p = 1;
	rgs.forEach((rg, p) => {
		// Set the RG value
		rg.value = arr[i][2*p + 3];
		// Set the RG label
		jQuery(document).ready(function(){
			if (p == 0) {
				jQuery("label[for=" + elem_id + "]").html(arr[i][2*p + 4]);
			} else {
				var elem_ext = '_' + (p);
				jQuery("label[for=" + elem_id + elem_ext + "]").html(arr[i][2*p + 4]);
			} // if
		});
	p++;
	}); // forEach
} // for i

but if you could get Darko's code working for me, that would be a more elegant solution. :)

Thanks again.

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

Populating a radiogroup programatically 11 months 2 days ago #237405

  • MarioPuco's Avatar
  • MarioPuco
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 5958
  • Karma: 119
  • Thanks: 554
Hey,

Glad you made it work.
I'll let Darko know but I cannot promise anything !

Regards,
Mario

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

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.048 seconds

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!