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
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>
0
Also Liked
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"]}
/>
2
Last Post!
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"]}
/>
2
Popular in Questions
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
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
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
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
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
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
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
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
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
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...
New
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
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









