Forums

Dynamic dropdown has to change other field from database

Invidia81 14 Aug, 2019
Hello,

I have a form to add an aquarium. Name and volume.
On ez calculator a dynamic dropdown with the aquarium name.
When changing the name of the aquarium i want to autofill the volume from the database.

You can test what i mean on:
https://www.dsrcalculator.nl you can login with demo:demo.

Thanks in advance.
healyhatman 15 Aug, 2019
There's a dynamic dropdown in the demos (Click New->Demo Form), have you had a look?
Invidia81 15 Aug, 2019
The dropdown is dynamic, data from database.
The text field has to change accordingly to selection, this is also data from database.
healyhatman 15 Aug, 2019
Use {var:blahblah} (replace with whatever you use to get your data) in the value of the field, and reload it when you change the dropdown.
Invidia81 15 Aug, 2019
So, i need a read_data1 (return pairs) for the dropdown and a read_data2 to populate the other field.

So when I select test, I should see 700 , showbak 300..... in the text field.

The dropdown value is {var:read_data1}
The textfield is {var:read_data2}

Dropdown change reload

Does not work....

Debug code gives:


Array
(
    [read_data1] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Data1`.`aid` AS `Data1.aid`, `Data1`.`name_aquarium` AS `Data1.name_aquarium` FROM `fxs74_chronoforms_data_aquariums` AS `Data1` WHERE `Data1`.`user_id` = '606' LIMIT 100;
                )

            [var] => Array
                (
                    [2] => test
                    [4] => showbak
                    [5] => nano
                    [6] => test123
                )

        )

    [read_data2] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Data2`.`aid` AS `Data2.aid`, `Data2`.`volume` AS `Data2.volume` FROM `fxs74_chronoforms_data_aquariums` AS `Data2` WHERE `Data2`.`user_id` = '606' LIMIT 100;
                )

            [var] => Array
                (
                    [2] => 700
                    [4] => 300
                    [5] => 50
                    [6] => 60
                )

        )

)
Invidia81 15 Aug, 2019
This solved my problem.

Thanks for all the help !
Invidia81 16 Aug, 2019
I had to go this way, the other option did not work as expected.

Use {var:blahblah} (replace with whatever you use to get your data) in the value of the field, and reload it when you change the dropdown.



I did everything like in the demo. The thing is the program reloads also my dynamic dropdown.
So it's going into a loop.
How to disable the reload event in advanced for my dynamic dropdown ?
healyhatman 16 Aug, 2019
Make sure your reload event is set to "standalone"
Invidia81 16 Aug, 2019
Ok, got some progress now ,thanks.
Now the field isn't populated by the database field.

I've put the form in attachement also the database.


​[file=http://www.dekock.pro/uploads/test_16_Aug_2019_12_45_03.cf6bak]Form[/file]
healyhatman 16 Aug, 2019
Sorry you also need to turn off "auto display view"
Invidia81 16 Aug, 2019
Thanks that's working !
Invidia81 16 Aug, 2019
I want to populate multiple fields now, when changing the first dropdown.
So far it worked with one value in a dropdown field.
When I change the dropdown field to a text field, nothing happens.

I changed the value from {var:read_data2 } to {var:read_data2.model2.volume}
and the read data to all matching records in place of pairs.


This is the array after reload from the dropdown.
Array
(
    [read_data2] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `model2`.`aid` AS `model2.aid`, `model2`.`user_id` AS `model2.user_id`, `model2`.`volume` AS `model2.volume` FROM `fxs74_chronoforms_data_aquariums` AS `model2` WHERE `model2`.`user_id` = '606' AND `model2`.`aid` = '9' LIMIT 100;
                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [model2] => Array
                                (
                                    [aid] => 9
                                    [user_id] => 606
                                    [volume] => 125
healyhatman 16 Aug, 2019
What have you got in the field value
Invidia81 17 Aug, 2019
I changed the value from {var:read_data2 } to {var:read_data2.model2.volume}
Invidia81 18 Aug, 2019
Please help me with this, part of my website is down because of this.
Should be a standard function of CF.

Thanks
healyhatman 18 Aug, 2019
Looks like you're returning all matching instead of first matching.
Invidia81 18 Aug, 2019
That's not working to.

The custom field in my dynamic page is

{view:field_text7} var only result disabled.

Is that correct and / or should I add something.
This topic is locked and no more replies can be posted.