Set the value when using the select Type
Set the value when using the select Type
mikedmason
Posts: 39Questions: 12Answers: 0
in Editor
Hi Guys,
I am using the select Type to have a drop down when i create or edit a record. How would i set the value to be the current database value if the user selects no? Or can I have it not update if the user sets it to no?
label: "Reset to default",
name: "user_data",
type: "select",
options: [
{ label: "Yes", value: "4545" },
{ label: "No", value: "user_data" }
]
Thanks
Mike Mason
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Mike,
The value used should be based on the
value
property (not thelabel
). So int he case above you would need to use:Is
user_data
just a fill you've put in for the above example, or is that actually the value that you would use in production code?Allan
Hi Allan,
user_data was just an example. What we are trying to achieve is a simple pin system. That a user can reset a users pin if needed. So I would like the a user to be able to select yes to reset the pin and no to leave it alone. So on an edit if they need to update the users name but not the pin then they would leave it as no. But on a new entry or edit they would set it to yes so it would set the default pin.
So would i put the editor.field( 'user_data' ).val( 'user_data' ); in the value section?
No, that won't work unfortunately as that function returns a field instance, not the value. It is also executed before the point at which the field would have any useful data in it.
One possible option is to set a predefined value for the No value and then remove it from the data submitted to the server if that value is selected - that means the libraries won't update that field. For example, using
preSubmit
:Would that work for you?
Allan
Hi Allan that would work. I will give it a go.
Thanks
Mike Mason