Issues with dynamic dropdowns

jpbhcom 25 Jun, 2019
[Edit]
I realize I titled this wrong, the dropdown isn't dynamic, just a database variable fed dropdown.


I've done this a dozen times, in CF4, 5 and twice now in CF6, however something changed between March and June. In a major way. I am now unable to produce dynamic dropdowns based off of the FAQs.
https://www.chronoengine.com/faqs/74-chronoforms/chronoforms6/5289-variable-shortcodes
https://www.chronoengine.com/faqs/58-chronoforms/cfv4/cfv4-elements-and-html/2647-how-do-i-build-a-select-drop-down-radio-button-or-checkbox-group
I'm using debug to view my queries results, they are producing what I expect to see.

[Case 1]
I'm following the standards, using the read_dataN (7 in my current case) variable in the Options section in my dropdown:
{var:read_data7}
This at best gives me options with an auto incremental value and Labels of "Array" in my dropdown, meaning it's not converting the the two columns I've set in the read_data as the value and Label.

[Case 2]
I've also attempted to load the data manually via PHP::
    $db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, date');
$query->from($db->quoteName('#__table'));
$query->where($db->quoteName('date') . ' > NOW()');
$query->order($db->quoteName('date'));
$db->setQuery($query);
$phpReturn = $db->loadAssocList();

return $phpReturn;
In my Options section I set it to the variable PHP name php4:
{var:php4}

This produces an array of expected data from my table, however, again, when I attempt to load the data in the dropdown array I get the same issue, the dropdown options value is auto incremental, and the Label is Array.

Either;
[A] What am I doing wrong?
[B] Is there another method to set values and labels to the dropdown via PHP directly?

Thanks,
JP
jpbhcom 25 Jun, 2019
Side note, I was able to break past the Array with my PHP var.

{var:php4.0}

Gave me the id as one label, and the date as the second.....
jpbhcom 25 Jun, 2019
   [php4] => Array
        (
            [returned] => Array
                (
                    [0] => Array
                        (
                            [id] => 2
                            [date] => 2019-06-26 10:00:00
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [date] => 2019-06-27 10:00:00
                        )

                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [id] => 2
                            [date] => 2019-06-26 10:00:00
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [date] => 2019-06-27 10:00:00
                        )

                )

        )
jpbhcom 25 Jun, 2019
Same issue with checkbox groups.
jpbhcom 25 Jun, 2019
Form settings:::
Published : On
Public : On

App Type ::: FORM
Follow pages order : OFF
Multi page form : OFF
Use AJAX : OFF
Enable server validations : ON
Check security fields : ON
Upload Files : ON
Log data : OFF
Debug : OFF
Enable permissions : OFF
Load default page if non found : OFF
jpbhcom 25 Jun, 2019
loadRowList() results in the same Array label, no value.
jpbhcom 25 Jun, 2019
I doubted it would work with the changes between CF5 and 6 but I did try to set value & text based off the FAQ >> Dynamic Data list:
https://www.chronoengine.com/faqs/58-chronoforms/cfv4/cfv4-elements-and-html/2647-how-do-i-build-a-select-drop-down-radio-button-or-checkbox-group

Old school:
    for($a = 0;count($results) > $a;$a++) { 
$form->data['field_select3'][$a]['value'] = $results[$a]['id'];
$form->data['field_select3'][$a]['text'] = $results[$a]['date'];
}
New school (just guessing at this point..):
    for($a = 0;count($results) > $a;$a++) { 
$this->set('field_select3 '.[$a].' value', $results[$a]['id']);
$this->set('field_select3 '.[$a].' text', $results[$a]['date']);
}
healyhatman 26 Jun, 2019
1 Likes
Your reload / autocomplete event needs to be set to "standalone"

Your read_data actions need to be set to return an array of key/value pairs
jpbhcom 26 Jun, 2019
Thanks healyhatman, I completely spaced the key/value pairs now that I read your post...
https://www.chronoengine.com/faqs/74-chronoforms/chronoforms6/5287-dynamic-dropdown-options

Looking again at this FAQ for dynamic dropdowns, I also see my mistake with my custom db's array...
It's important to breakdown the multidimensional array into a single associative array.... DERP.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger