Need The First Option in a Radio Group to be Selected

How to pre-select the first option in a ChronoForms radio group when the values are dynamic.

Overview

The issue occurs because the radio group values are generated from a data source in descending order, and the form does not automatically select the first value when the selected value field is left empty.
Add a PHP action after the data source to find the largest value in the array, then reference that PHP action variable in the radio group's selected value field.

Answered
ChronoForms v6
cr cre8tivemedia 05 Sep, 2018
I've set a radio group array to arrange the values in descending order. I would like to have the first value (the largest number) to be pre-selected. I've tried a number of things in the "selected value" field but can't figure out the proper syntax. I can get it to work if I know ahead of time what the largest number will be... unfortunately, with the array this number changes constantly.
Any thoughts?

Thanks,
Matt
he healyhatman 06 Sep, 2018
Well it should be var read data, definitely not var radio.

Put a debug in as the last action on page load and post it
he healyhatman 06 Sep, 2018
So if you don't put anything in selected value and you don't put an empty option at the top it should ALREADY be selected. So if you don't put anything in the selected value box, what happens for you?

Either that OR put a PHP action after your read data, loop through ($this->get("read_data10", "deault")), return the largest number, and then in Selected Value put {var:phpaction}
cr cre8tivemedia 06 Sep, 2018
If I leave the selected value field blank then nothing is selected

Need The First Option in a Radio Group to be Selected image 3

I tried adding a php action after the read data like this -

Need The First Option in a Radio Group to be Selected image 4

and changed the selected value -

Need The First Option in a Radio Group to be Selected image 5

this is the result -

Need The First Option in a Radio Group to be Selected image 6
he healyhatman 06 Sep, 2018
You can't just put that in the PHP action you have to actually put code in there. That code I gave you was how to get the array you were after, now you need to search through it
cr cre8tivemedia 06 Sep, 2018
Sorry, wish I understood a little better but not as versed as I'd like to be. I need to add additional code to the PHP action or do I add it in javascript?

something like this in PHP?
echo(max(array(var:read_data10));
he healyhatman 07 Sep, 2018
Answer
1 Likes
return max(array_keys($this->get("read_data#", "")));

Don't copy paste, you need to type it manually. The forums adds in invisible characters.
cr cre8tivemedia 07 Sep, 2018
Thanks again healyhatman, took me a little bit but I finally got it to work.
Still not that used to dealing with PHP but I'm learning.
This topic is locked and no more replies can be posted.