Wrong selected value in Dropdown

Set a preselected value in a ChronoForms dropdown.

Overview

The dropdown incorrectly interprets numeric strings as integers, causing mismatches when trying to preselect an option by its key or value.
To ensure correct selection, modify the data source so the value field is not a simple integer. Use a CONCAT function to create a unique, non-numeric string for the value, preventing automatic type conversion.

Answered
ChronoForms v6
Lo Lorentz 15 May, 2018
Hi,

I looked up informations in FAQ and forum about the field Selected Value in drop down field but I found nothing solving (one of) my problem(s).

If I set a selected value (with php or custom form), I never get the right key/value expected.

To make tests, I tried with a simple dropdown. Originally, options are fed by a read_data key/value but I did it manually for this example below.

Wrong selected value in Dropdown image 1


By this way, I thought the dropdown would display le label "21", 22 being the key, or would display 22 like I wrote in the field (and the value key 23).

But this is the result :

Wrong selected value in Dropdown image 2

I've changed the multi select dropdown option to YES and I don't understand the result :

Wrong selected value in Dropdown image 3

I only put one value in the selected value list and there is three selected.


Any idea of what I did wrong ?

Thanks
Lo Lorentz 16 May, 2018
Hi,

I am still stuck on this.

No one see the mistake i've done ?
Lo Lorentz 17 May, 2018
Well, still stuck ...

I did quite a lot of tests without results and hardly I think I've found a way to identify the problem but I don't know how to solve it.

I did this options List and selected in a dropdown :

Wrong selected value in Dropdown image 4

the result is :

Wrong selected value in Dropdown image 5

I identify two problems :
  1. dropdown doesn't use my argument "07" as is, means like a string, It probably changes it before the array search in a numeric value : 7. This is why it doesn't offer me the options 10=07.
  2. I can't specify where to look, key or field, and it seems to do both, so I obtain the image result above.

How can I solve this problem ?
Lo Lorentz 18 May, 2018
Answer
I partially solved my problem using a CONCAT in field to retrieve in the read_data feeding the dropdown.

In my case :
id
Concat(departement_code , ' ' , departement_nom)
instead of
id
departement_code

In this way, there's no more unique integer in the value field of the dropdown and no more problems.

So I put this topic on "answered" even if it's not really the case ...

Either I missed something and I don't understand how to fully use the dropdown arguments
Or it's an unexpected behaviour that need to be solved in an update ...

I hope I'll know one day ...

Thanks for the support ...
This topic is locked and no more replies can be posted.