ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Populate Radio Groups Based on Dropdown Selection

cre8tivemedia 16 Oct, 2018
I have a dropdown which is reading from two different categories (catid: 12 and catid: 13) and grabbing the "created_by_alias" field in my database. I would like the two radio groups that are in different categories (catid: 12 and catid:13) to show the "title" field with only the options that would match the selected "created_by_alias" field from the dropdown. Is there a tutorial anywhere on how I accomplish this or can anyone give me any pointers?

Here is a screenshot -

frontend.png

Thanks,
Matt
CFv6
Joomla 3.8.13
healyhatman 17 Oct, 2018
It's pretty much the same as for populating a dropdown from a database read.
cre8tivemedia 17 Oct, 2018
Ok, so I do a read from the dropdown?
set the options to {var:field_select13}
Do I need to set up an event onchange trigger and run a function?
Sorry, first time attempting this

Matt
healyhatman 17 Oct, 2018
Have a look at the dynamic dropdown demo form, just use a radios group instead of the second dropdown.
cre8tivemedia 18 Oct, 2018
Thanks healyhatman, didn't realize there was a demo... I've modified the demo to test out what I am trying to do and I'm just lost on the syntax for the options in the second dropdown. I need something like this:
$options = [];
switch($this->data('what_do_you_think')){
$options = 'data6.title';
}
return $options;

I know this is not correct but I'm going in circles trying to figure out how this is supposed to be. My first dropdown is pulling the data from {var:read_data7} and it is working as I intended grabbing from 'data6.created_by_alias' and 'data6.introtext' from the database. I'd like to have the second dropdown show the 'data6.title' in 'catid:12' as options based on the 'data6.created_by_alias' selection. I'm hoping I explained that correctly...

thanks,
Matt
healyhatman 18 Oct, 2018
Needs to return an array, you've just set options to a string.
cre8tivemedia 18 Oct, 2018
ok, so I assume I need another read data?

I've tried this with a new read data -
$options = [];
switch($this->data('what_do_you_think')){
$options = '{var:read_data8}';
}
return $options;
pretty sure my syntax is messed up tho, can't figure out where I'm going wrong...
healyhatman 18 Oct, 2018
I too am pretty sure you have that syntax wrong why do you have a switch statement in there
cre8tivemedia 18 Oct, 2018
Yeah, sorry I'm not very well versed with php but I'm trying to learn... I was trying to modify the demo for a dynamic dropdown which has options that are set right in the code.
$options = [];
switch($this->data('what_do_you_think')){
case 'good':
$options = ['1' => '1', '2' => '2', '3' => '3'];
break;
case 'bad':
$options = ['-1' => '-1', '-2' => '-2', '-3' => '-3'];
break;
case 'so':
$options = ['good' => 'Good', 'bad' => 'Bad'];
break;
}
return $options;
I'll be honest, I'm completely lost on how the syntax is supposed to look. I've been scouring the forum but cannot find a similar situation to emulate.
healyhatman 19 Oct, 2018
Looks fine, what have you got in the options list of your radio field, what have you got in your reload action, what IS it doing?
cre8tivemedia 19 Oct, 2018
What looks fine? My code or the demo code? I was just showing what was in the demo because you asked why I was using the switch statement...
I've been modifying the demo code to see if I can get this to work
this is what I currently have -

dropdown1.png

dropdown1a.png

dropdown2.png

dropdown2a.png

read-data7.png

read-data8.png

php.png
healyhatman 19 Oct, 2018
in the radio options change it to {var:read_data#.model} replacing # and model with whatever they're supposed to be the writing is tiny and I'm tired
cre8tivemedia 19 Oct, 2018
changed it to -
$options = [];
switch($this->data('what_do_you_think')){
$options = '{var:read_data8.data6.created_by_alias}';
}
return $options;

still not working...
Am I supposed to change the switch statement to something else or remove it?
healyhatman 19 Oct, 2018
you can't use shortcodes in PHP. $this->get("blahblah", "") instead.

The switch statement is like saying if $variable is A, do this. If it's B, do this. If it's C etc etc. the way you have it now won't work.

Do you have a custom code block after it with {view:field_identifier}?
cre8tivemedia 23 Oct, 2018
ok now I have -
$options = [];
($this->get('what_do_you_think')){
$options = '{var:read_data8.data6.created_by_alias}';
}
return $options;
There is a custom code after it that was already there from the demo
{view:field_select2}
and in the dropdown called "field_select2" I have
{var:options}
0=None
I can see the second dropdown (field_select2) which is only populated with the "None" option and when I select an option from the first dropdown (field_select1) I just get a spinning wheel as if it is searching...
healyhatman 23 Oct, 2018
When I said you can't use shortcodes in PHP I meant you can't use {var:xxxxxx}.

Also your code makes absolutely no sense🙂

You don't even need the PHP in there, now that I've understood more clearly what you're trying to do. Get rid of the PHP block, and in your dropdown field_select2, put
{var:read_data8}

Make sure your read data action is set to "Return an array of key/value pairs"
cre8tivemedia 23 Oct, 2018
That puts me back to where I originally started...
The picture in my first post explains what I'm trying to do. I want the first dropdown to show the "created_by_alias" field from two categories (this I already have set). After selected, I would like the second dropdown to show everything that matches the first dropdown selection but display the "title" field associated with the first selection in just one of those categories.

I have a store name set as the "created_by_alias" field which falls in multiple categories (this is the first dropdown)
when the store name is selected I want the second dropdown to show the multiple "title" options from category 12 that are associated with the store name
and third dropdown to show category 13

Hope I explained that correctly
healyhatman 23 Oct, 2018
Hang on sorry let me try make sure I have this.

On Load: Read data --> Display Dropdown 1

On selecting something from Dropdown 1: Read data based on Dropdown 1 selection--> Display Dropdown 2

On selecting something from Dropdown 2: Read data based on Dropdown 2 selection --> Display radio buttons

Is that right? All you're stuck with is trying to get the right information displayed on the Radio buttons?
cre8tivemedia 23 Oct, 2018
Sorry if I'm confusing... I was using dropdowns for everything because I assumed I could use the
same data in a Radio Button later once I figured out the code...

This is what I would like -

On Load: Read data --> Display Dropdown 1 (cat12 & cat13 "created_by_alias")

On selecting something from Dropdown 1: Read data based on Dropdown 1 selection--> Display Radio Buttons 1 (cat12 "title")

On selecting something from Dropdown 1: Read data based on Dropdown 1 selection--> Display Radio Buttons 2 (cat13 "title")

I would like two separate radio buttons based on the initial selection in Dropdown 1
healyhatman 24 Oct, 2018
OK so you should be able to do that. In your event tab of the drop down, where you have the onchange->reload event, put the names of the two radio select fields on separate lines like this in the field identifier
myRadioField1
myRadioField2
In the "reload event" field of each of those radio fields you'll need separate events, one for the first radio select group and one for the second. Then put in the requisite {var:read_data#} in their options
cre8tivemedia 27 Oct, 2018
Do I need a php action for this to work? I've been trying all kinds of different things in the options box of the radio group and the only thing I can get to work is if I read directly from the {var:read_data7} function but this just loads the same fields that I have in the 1st dropdown and nothing happens when I make a selection... I can't figure out the syntax to get {var:read_data7.title} or {var:field_select1.title} based on the selection in the 1st dropdown.

I've set the onchange and the reload events as you have suggested but am getting nowhere. I can see the radio group but it stays blank

Here is a frontend view
http://coupons.cuttingcoupons.net/index.php?option=com_chronoforms6&chronoform=dynamic-test
healyhatman 27 Oct, 2018
Show me the read data action in the event that you use to reload the radio fields, and the name of the fields you want for the value and the label
cre8tivemedia 28 Oct, 2018
I'm able to get the data from the first pulldown into the first radio group, so I've gotten somewhere...

This is the read data that I used to populate the radio group -

load_discount.png

The 1st pulldown (storename) shows the "created_by_alias" field from the DB. You can see below that the store "A Pea in the Pod" is showing up twice. There are two instances where this happens to be the "created_by_alias". I'd like to just show the field once in the pulldown and have the radio group show the multiple "title" fields from a specific "catid" field in the database (catid = 12)


duplicates.png



So, the user selects "A Pea in the Pod" from the pulldown and the radio group would show the following "title" fields from "catid"12
Up to 26.65% Off  A Pea in the Pod Gift Cards  - (Cardcash)
A Pea in the Pod - Get Up To 1.0% Cash Back (Ebates)



Currently it seems to be only showing the one "title" from each selection

selection.png



The value of each radio group selection is in the "introtext" field of the database which would be 26.65 and 1.0 for the examples shown above

Here is the database -

DB.png
healyhatman 28 Oct, 2018
Answer
If you want only one "A Pea in the Pod" to show up you will need to retrieve DISTINCT(model.field_name):model.alias

And try using created_by_alias as your dropdown value and in your where condition, since it looks like you're using "title" which again appears to actually be "Up to 26.5% blahblahblah"

Also I wouldn't use introtext, I'd use the id for the value of the radio group.
cre8tivemedia 03 Nov, 2018
That did the trick, I was getting hung up on the syntax for the where conditions in my read event but I figured it out. For anyone wondering this is what I came up with to pull the correct data:

where.png

"storename" being the ID of my dropdown
"created_by_alias" and "catid:12" the fields in the database
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com