Modifiy an option in a select
Hello,
Is it possible to change one of the options in select to show the user the active number.
12 Replies
I have probably to use ->getOptionLabelUsing but how can I replace one value in the query?
Hi @pasteko, something like this could work :
according to the docs this should work:
Thank you, I'll try that if I can't get it working with ->getOptionLabelUsing
Sorry I don't understand where's the condition here?
Not 100% sure but it seems like
getOptionLabelUsing()
would run for the currently selected item (before save), whereas the snippet above would add the (active)
suffix after save.that will only be run if the label isnt already present in the preloaded options
ah, nevermind then.
So the solution is to build my options manually with conditions?
Maybe my explanation was wrong, I don't need the selected or default value, the active state comes from a value in the numbers table.
I'm trying to populate the select with a relation and show the user the actual (active) number.
If the options are coming from the DB and the active status is a column in the table, something like this might work :
Thank you, it's working perfectly!