Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displayed selected label does not change after first selection #77

Closed
camfeghali opened this issue Aug 13, 2024 · 6 comments
Closed

Displayed selected label does not change after first selection #77

camfeghali opened this issue Aug 13, 2024 · 6 comments

Comments

@camfeghali
Copy link

camfeghali commented Aug 13, 2024

I have the following setup (In a live component).

<.simple_form
  for={@form}
   id="draft_order-form"
   phx-target={@myself}
   phx-change="validate"
   phx-submit="save"
   >
     <.live_select placeholder="Search by Email" field={@form[:customer_id]} label="Customer" phx-target={@myself} />
</.simple_form>

...

  @impl true
  def handle_event("validate", %{"draft_order" => draft_order_params} = rest, socket) do
    changeset =
      socket.assigns.draft_order
      |> DraftOrders.change_draft_order(draft_order_params)
      |> Map.put(:action, :validate)

    {:noreply, assign_form(socket, changeset)}
  end
  
  ...
  
    @impl true
  def handle_event("live_select_change", %{"text" => text, "id" => live_select_id, "field" => live_select_field}, socket) do
    options =
      case live_select_field do
        "draft_order_customer_id" -> MyApp.Customers.search_by_email(text) |> Enum.map(& {&1.email, &1.id})
        "draft_order_tags" -> [{"Refund", :refund}, {"Lost Item", :lost_item}]
      end

    send_update(LiveSelect.Component, id: live_select_id, options: options)

    {:noreply, socket}
  end

The displayed selection works fine when i search and select the first customer, but stays the same on subsequent searches and selection

Any help would be much appreciated

@pau-riosa
Copy link

On validate handle_event, you still need to send_update just like what you did on live_select_change.

@maxmarcon
Copy link
Owner

maxmarcon commented Aug 13, 2024

On validate handle_event, you still need to send_update just like what you did on live_select_change.

Mmmh not really. Hard to say what's going on.

What live view version are you on? What live select version?

Sharing a minimal repo that reproduces the issue would help a lot.

@camfeghali
Copy link
Author

Hey thanks for getting back to me, i'm working on producing a minimal repo, until then, I'm using

{:phoenix_live_view, "~> 0.20.17"},
{:live_select, "~> 1.0"}

@camfeghali
Copy link
Author

I actually updated to live_select 1.4 and it works!

@maxmarcon
Copy link
Owner

This doesn't tell me which versions are installed :) You should run: mix deps

@maxmarcon
Copy link
Owner

I actually updated to live_select 1.4 and it works!

Yep, always try the latest version before submitting a bug report :) it saves time! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants