# Default value Select Input

**URL:** <https://forum.elixirforum.com/t/default-value-select-input/71607>\
**Category:** Questions\
**Tags:** phoenix, phoenix\_html, learning-elixir, phoenix\_live\_view\
**Created:** [July 8, 2025, 8:06am UTC](https://forum.elixirforum.com/t/default-value-select-input/71607 "2025-07-08T08:06:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabricedge1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fabricedge1/32/38608_2.png) [@fabricedge1](https://forum.elixirforum.com/u/fabricedge1)\
**Post date:** [July 8, 2025, 8:06am UTC](https://forum.elixirforum.com/t/default-value-select-input/71607/1 "2025-07-08T08:06:47Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![fabricedge1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fabricedge1/32/38608_2.png) [@fabricedge1](https://forum.elixirforum.com/u/fabricedge1)\
**Post date:** [July 8, 2025, 10:57am UTC](https://forum.elixirforum.com/t/default-value-select-input/71607/2 "2025-07-08T10:57:50Z")

</div>

[\> GITHUB: core\_components.ex](https://github.com/phoenixframework/phoenix/blob/1f969b5ed7584b61c8c1934108d865ed0ea65735/installer/templates/phx_web/components/core_components.ex#L208)  
I took reference from this. I am not sure if .input is the best approach for what i wanted to do, then i am using select for this this case where i need default value 🙂

---

<div class="post-metadata">

**Author:** ![fabricedge1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fabricedge1/32/38608_2.png) [@fabricedge1](https://forum.elixirforum.com/u/fabricedge1)\
**Post date:** [July 8, 2025, 10:57am UTC](https://forum.elixirforum.com/t/default-value-select-input/71607/3 "2025-07-08T10:57:54Z")

</div>

Way out: `<select id="theme" name="theme" class="" multiple > {Phoenix.HTML.Form.options_for_select([{"Roxo", "purple_theme"}, {"Vermelho Padrão", "default_theme"}], @theme )} </select>`  
I dont know how to make select have a dropdown menu as .input

> [Phoenix.HTML.Form](https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html#options_for_select/2)

Found this at core\_components.ex ` def input(%{type: "select"} = assigns) do ~H""" <div> <.label for={@id}>{@label}</.label> <select id={@id} name={@name} class="mt-2 block w-full rounded-md border border-gray-300 bg-white shadow-sm focus:border-zinc-400 focus:ring-0 sm:text-sm" multiple={@multiple} {@rest} > <option :if={@prompt} value="">{@prompt}</option> {Phoenix.HTML.Form.options_for_select(@options, @value)} </select> <.error :for={msg <- @errors}>{msg}</.error> </div> """ end`

---

<div class="post-metadata">

**Author:** ![fabricedge1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fabricedge1/32/38608_2.png) [@fabricedge1](https://forum.elixirforum.com/u/fabricedge1)\
**Post date:** [July 8, 2025, 10:39pm UTC](https://forum.elixirforum.com/t/default-value-select-input/71607/4 "2025-07-08T22:39:55Z")

</div>

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>`

---

<div class="post-metadata">

**Author:** ![fabricedge1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fabricedge1/32/38608_2.png) [@fabricedge1](https://forum.elixirforum.com/u/fabricedge1)\
**Post date:** [August 4, 2025, 1:21am UTC](https://forum.elixirforum.com/t/default-value-select-input/71607/5 "2025-08-04T01:21:52Z")

</div>

other way around:

```elixir
  <.form for={@form} id="main-form" phx-submit="save" phx-change="validate" class="space-y-6">
     <div >
       <label>@privacy_options</label>
       <.input field={@form[:theme]} type="select" options={@theme_options} />
    </div>
  </.form>

```

---

<div class="post-metadata">

**Author:** ![joshua-bouv](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joshua-bouv/32/27787_2.png) [@joshua-bouv](https://forum.elixirforum.com/u/joshua-bouv)\
**Post date:** [August 4, 2025, 10:02am UTC](https://forum.elixirforum.com/t/default-value-select-input/71607/6 "2025-08-04T10:02:54Z")

</div>

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

```elixir
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’

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

```
