This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

SinisaPerovic
SinisaPerovic

Hi.

This post https://octobercms.com/forum/post/dropdown-shows-its-value-than-key-name-in-list-controller there is a solution for list controller to display values instead of keys from dropdown in forms.

Although this works fine, it generates another problem. When editing a record, dropdown in the form does not display selected value. Instead it shows an empty dropdown (default value) to select the options, while the filed in the database has a proper key value. When I remove aforementioned code from my model, and get back to having keys in my list controller, the dropdown is correctly populated when editing.

Any help would be appreciated.

Cheers.

marco.messa325452
marco.messa325452

Ok I managed this thanks to this

https://stackoverflow.com/questions/40799476/show-dropdown-value-in-listing-search-instead-of-dropdown-key-using-builder-plug

Simply, not use any method in your model, instead in in your columns.yaml use select with a custom SQL query:

homecol:
        label: 'Colonna Home'
        type: text
        searchable: true
        sortable: true
        select: CASE WHEN (homecol =  '0' ) THEN 'Nessuna' WHEN (homecol = '1') THEN 'Sinistra' ELSE 'Destra' END

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.