Sidi_Mohammed

Sidi_Mohammed

Hello everybody,
Iam new to Phoenix Components, I have tried form inside LiveView and it was amazing, but I have an issue :
form is created by Phoenix.Component.to_form/2 which transform a changeset to a form and we can use <.input type = "text" field = {@form[:somefield]} to represent a form’s field and the user’s data will be found in handle_event("submit", %{"user" => data}, socket) after submitting the form, Okay that’s fine.
But how about other inputs types than <.input type = "text"> ?
For example if we want to implement a template where someone can Signup a new account :
he has some <.input type = "text">s like username, email, password and he has to choose from a “Radio Button” between Man and Woman and he has to choose a date of birth from “Scroll Lists”…
So how we can implement that ? and the most important how we can retrieve user’s entered data in handle_event("submit"....) ?
I have searched about and I couldn’t find docs or examples, so I will be thankful for your answers.

Showing Posts 1 to 10

codeanpeace

codeanpeace

With the new core components like <.input ...> and <.modal>, they’re just functions that are defined and documented within your Phoenix app in lib/hello_web/components/core_components.ex .
https://github.com/phoenixframework/phoenix/blob/f8c0ad26ee031ee87a6e7307f6dc1f7722134dd5/installer/templates/phx_web/components/core_components.ex#L227-L264
So while the type attribute defaults to "text", it also accepts a whole bunch of other values including "radio" as well as "date".

  attr :type, :string,
    default: "text",
    values: ~w(checkbox color date datetime-local email file hidden month number password
               range radio search select tel text textarea time url week)
Sidi_Mohammed

Sidi_Mohammed OP

Thank you @codeanpeace,
Considering we have used no-text type for an <.input> for example “Multi Select List”, how we can retrieve user’s input in handle_event/3 after submitting ?

jmnda

jmnda

Hi @Sidi_Mohammed , kindly asking if you can elaborate more or provide more context on your question, perhaps even a simple example of what you are trying to archieve?

Sidi_Mohammed

Sidi_Mohammed OP

@jmnda I gave an example of Signing up

jmnda

jmnda

Just want to understand what you mean here:

Are you trying to implement a Multi Select input?

Sidi_Mohammed

Sidi_Mohammed OP

Exactly @jmnda, I want to implement a list which the user can select multi values, how we can implement that please ? and how we can retrieve the selected values in handle_event/3 when submitting the form ?

Joep

Joep

Did you search for it on these forums?
https://forum.elixirforum.com/search?q=Multi%20select

jmnda

jmnda

Use can pass a multiple attribute to your input with options to select, for example:

<.input field={@form[:tags]} type="select" multiple options={[:item_1, :item_2, :item_3]} label="Tags />

As @Joep suggested, you can search on the forum, alternatively you can look at this guide, or checkout this library

codeanpeace

codeanpeace

Here’s how you can discover it for yourself!

# assuming your multi-select is within the existing user form
def handle_event("submit", %{"user" => data}, socket) do
  IO.inspect(data)
  # and optionally when running `iex -S mix phx.server`
  require IEx; IEx.pry
  ...
  {:noreply, socket}
end

# or more generally
def handle_event("submit", params, socket) do
  IO.inspect(params)
  ...
end
Sidi_Mohammed

Sidi_Mohammed OP

I sword I have thinked the same thing to show the data’s map and see what’s happening :joy::joy:, Iam just waiting until turn on my computer,
thank you a lot again @codeanpeace

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews