shortlyportly

shortlyportly

What causes phx-no-feedback to be automatically removed?

Hi

I have a complex form in which I have multiple budget components that are displayed using as follows:

<%= for budget <- inputs_for(f, :budgets) do %>
        <div>
          <%= live_component @socket, SageWeb.NominalLive.BudgetComponent,
                id: "budget-#{input_value(budget, :year)}",
                parent_id: @id,
                budget: budget,
                company_id: @company_id,
                view: __MODULE__

        %>
        </div>

One of the fields on the budget component can trigger an event:

<%= input @budget, :annual,
      phx_target: @myself,
      phx_keydown: "annual-budget-change",
      phx_debounce: "blur",
    %>

Note: The input tag is just a convenience helper that combines input and error tags.

In the budget component I have the following code (cut down for simplicity purposes).

def handle_event("annual-budget-change", params, socket) do
    params = %{"annual" => params["value"]}

    changeset = Budget.annual_changeset(socket.assigns.budget.source, params)

    case Ecto.Changeset.apply_action(changeset, :validate) do
      {:ok, _budget} ->
        {:noreply, socket}

      {:error, changeset} ->
        budget =
          socket.assigns.budget
          |> Map.put(:source, changeset)
          |> Map.put(:errors, changeset.errors)
          |> Map.put(:params, params)

        {:noreply, assign(socket, :budget, budget)}
    end
  end

This all works reasonably well BUT errors are not being displayed. I’ve tracked it down to the fact that the phx-no-feedback class isn’t being removed as it would be for standard form processing. If I manually remove the class via Dev Tools I can see the error.

So a couple of questions if I may:

  • Am I not setting something correctly which would cause the error to display?
  • Is what I’m doing a bit mad/off the beaten path and shouldn’t be done?

cheers

Dave

First Post!

soup

soup

I have seen this a few times and I’m afraid I can’t remember the fix exactly.

Possibly it depended on passing the changeset through form_for? Unclear if you’ve dropped that for the post or if you’re not using it.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement