fabricedge1

fabricedge1

Default value Select Input

Question: Is there a default value that a option can have in select component? I am using LiveView

 <.input field={@form[:theme]} value={"Roxo"} type="select"
                  options={[
                    {gettext("Vermelho Padrão"), "default_theme"}, {gettext("Roxo"), "purple_theme"}, {"Verde", "green_theme"}
                    ]} />

Marked As Solved

fabricedge1

fabricedge1

remove “multiple” from select and dropdown works: <select id="theme" name="theme" class=""> {Phoenix.HTML.Form.options_for_select([{"Roxo", "purple_theme"}, {"Vermelho Padrão", "default_theme"}], @theme )} </select>

Also Liked

joshua-bouv

joshua-bouv

To set a default value, you do this in the form.

def mount(_params, _session, socket)
  changeset = User.changeset(user, %{theme: "Dark"})
  {:ok, assign(socket, form: to_form(changeset))}

If you are looking to set a default value that isn’t one of the options, you can add a prompt. Ie ‘Choose xxx’

<.input
  field={@form[:theme]}
  type="select"
  prompt="Choose a theme..."
  options={["Light", "Dark"]}
/>

Last Post!

joshua-bouv

joshua-bouv

To set a default value, you do this in the form.

def mount(_params, _session, socket)
  changeset = User.changeset(user, %{theme: "Dark"})
  {:ok, assign(socket, form: to_form(changeset))}

If you are looking to set a default value that isn’t one of the options, you can add a prompt. Ie ‘Choose xxx’

<.input
  field={@form[:theme]}
  type="select"
  prompt="Choose a theme..."
  options={["Light", "Dark"]}
/>

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement