@Gazler
Thank you, finally I managed the options to work even with optgroups. Probably I was passing wrong keyword list to the select/4 helper.
Now I can use something like:
[
[key: "Choose a color", value: "", disabled: true],
set1: [
[key: "White", value: "white"],
[key: "Black", value: "black"],
[key: "Gray", value: "gray"]
],
set2: [
[key: "Blue", value: "blue"],
[key: "Red", value: "red"],
[key: "Green", value: "green"]
]
]
or even shorter
[
[key: "Choose a color", value: "", disabled: true],
set1: [:white, :black, :gray],
set2: [:blue, :red, :green]
]
And with the following function I’m able able to better automate the whole thing. ^^
def collection(options, prompt \\ "Please choose an option", disabled \\ true),
do: [[key: prompt, value: "", disabled: disabled]] |> Enum.concat(options)
The param “options” can be anything I would pass as options to select/4