refer to a dropdown value to pass as parameter to event

How to store a dropdown's label instead of its key in a database.

Overview

The issue occurs because a dropdown stores its key (like 'n', 'h', 'v') in the database, but the user needs to save the corresponding human-readable label (like 'Normal', 'High') for better display.
Create a custom PHP code to map the key to its label and set a new data variable before saving. For dynamic dropdowns populated from a table, you will need to query the table to retrieve the label based on the selected key.

Answered
Connectivity v6
gi gix.vax 05 Mar, 2020
Hi all
i have dropdown well populated that feed a field in a table
name of dropdown: priority_accepted1
[strong]VALUES
n:Normal
h:High
v:Very High[/strong]
it works ok and save the keys n, v or h in database

now i need to save in a field of another table, a text composed by the value (not the key) and something else

in an avent (Change_priority) i put
{fn:save_evento_chat$descrizione_evento=Priority changed to (data:priority_accepted1) (n-Normal h-High v-Veryhigh)}
if for example i choose VeryHigh it store
Priority changed to v (n-Normal h-High v-Veryhigh)

it works ok
but for a better visualization i would like to store something like
Priority changed to Normal
Priority changed to High
Priority changed to Very High

i tried
{fn:save_evento_chat$descrizione_evento=Priority changed to (data:priority_accepted1.value) }[br] but it doesn't work[br][br]is there a way to take the value from dropdown and not the key?

thank you
gi gix.vax 05 Mar, 2020
Answer
i solved in this way
created a custom code in php that populate a data value {data:priority_data} and call it before the function with parameters
if you need it is this
<?php
$priority=$this->data("priority_accepted1");
if ($priority=='n'){
$this->set("priority_data","Normal");
}
if ($priority=='h'){
$this->set("priority_data","High");
}
if ($priority=='v'){
$this->set("priority_data","Very High");
}

now, for a dropdown populated from table i need the same but i think i have to read again from table filtering value from dropdown

the start answer remain, changing a bit:
Is there a way to store the value of dropdown before the form is sent?
Not the key, the value.
he healyhatman 06 Mar, 2020
You mean the LABEL. The "value" IS the key.

And no, not without javascript.
gi gix.vax 07 Mar, 2020
hi healyhatman

yes i mean label

for now i mark as solved

p.s.
if someone have a javascript already written, post it please.
This topic is locked and no more replies can be posted.