budgie

budgie

Value from form-associated custom element not included in form params on submit

I’m using a custom element for duration selection. It has a few buttons that modify the value. When I inspect the params from the phx-submit event, there is no value included from the custom element. I want it to be treated as a standard text input with an integer value. How can I get its value included in the submission?

Value from form-associated custom element not being included in form params on submit

Here is the code from the render function of the live component I created that wraps the custom element:

  def render(assigns) do
    ~H"""
    <div id={@id} class="flex items-center gap-4">
      <duration-input name="duration" value={@minutes}></duration-input>
      <TimeBoxWeb.Icons.pipe class="h-5 stroke-shady-white/40" />
      <fieldset class="flex items-center gap-2">
        <%= for {name, value} <- durations() do %>
          <button
            type="button"
            class="option"
            phx-click="set_duration"
            phx-value-minutes={value}
            phx-target={@myself}
            tabindex="-1"
          >
            <%= name %>
          </button>
        <% end %>
      </fieldset>
    </div>
    """
  end

Marked As Solved

budgie

budgie

For anyone reading this, I came across the solution. My form-associated custom element was missing calls to ElementInternals.prototype.setFormValue. Since the form-associated custom element API is relatively new and unused, there is not much information available online. Here is a google doc that goes over the form participation API for event-based participation and form-associated custom elements.

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
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
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement