liveview-native / liveview-client-swiftui

MIT License
376 stars 37 forks source link

[Bug]: Button click event change value in input form #1473

Open pierre2202 opened 1 week ago

pierre2202 commented 1 week ago

What happened?

`  <.simple_form for={@form} id="login_form" action={~p"/users/log_in"} method="post">

<.input style="frame(width: 225) disabled(true)"  field={@form[:pin]}  value={@pin} type="SecureField" label="Pin"> </.input> 
<.simple_form/>
 <Button  phx-click="1" phx-value-v="1" >1 </Button>

Hello , when i click on the button in macos lvngo the value doesnt change all the time, in ios lvngo the first time value dont change but after the value change with a gap. The problem is only in a form.

if i write this code all is ok but that is not normal

def handle_event("1", %{"v" => v}, socket) do
    send(self(), "test")
    cond do
      v == "cancel" ->
        s = String.length(socket.assigns.pin)
        s = String.slice("elixir", 0, s-1)

        {:noreply,  socket |> assign(pin: s)}
      v == "reset" ->
        {:noreply,  socket |> assign(pin: "")}

        true ->
  {:noreply,  socket |> assign(pin: socket.assigns.pin <> v)}

      end

end

def handle_info("test", socket) do

  {:noreply, socket |>  push_patch(to: ~p"/users/log_in")}

end

Library Version

last

Xcode Version

last

Swift Version

last

On which device or simulator are you running into the problem?

iPhone, MacOS

Target Device Operating System Version

last

Relevant log output

No response

bcardarella commented 1 week ago

@pierre2202 we just published LVN Go for MacOS 0.3.1 that included the 0.3.1 release of the client that I think will solve this problem. Can you confirm your LVN Go version to see if this resolves your issue?

pierre2202 commented 1 week ago

i updated with the last version 0.3.1 all liveview native but the problem is always here, i did a mix deps ,compiled and relaunched the server

bcardarella commented 1 week ago

can you share an example app for us to quickly diagnose?

pierre2202 commented 1 week ago

of course link of the app

user_login_live.ex

pierre2202 commented 1 week ago

i tried a swift method ,that work better with lvngo ios but sometimes not . In macos that dont work. front end : <SecureField style={["frame(width: 225)","disabled(true)",~s[focused(attr("focus"))]]} focus={@focus} text={@pin} name="pin">Pin</SecureField>

back end

def handle_event("1", %{"v" => v}, socket) do
    socket =
      socket |> assign(focus: "false")

    send(self(), {"test", %{v: v}})

    {:noreply, socket}

end
def handle_info({"test", %{v: v}}, socket) do
  cond do
    v == "cancel" ->
      s = String.length(socket.assigns.pin)
      s = String.slice(socket.assigns.pin, 0, s-1)

    socket =  socket |> assign(pin: s)
    {:noreply, socket |> assign(focus: "true") }
    v == "reset" ->
      socket = socket |> assign(pin: "")
      {:noreply, socket |> assign(focus: "true") }

      true ->
socket =  socket |> assign(pin: socket.assigns.pin <> v)
{:noreply, socket |> assign(focus: "true") }

      end
end
bcardarella commented 1 week ago

@pierre2202 unfortunately Carson (our Swift dev) was dealing witth Hurricane Milton and lost power. I'm hoping he'll be back next week and I'll have him take a look at this.

I did take a look at the app you linked but it was very large. It would be helpful if you could isolate this issue in an example app that only has the relevant code. Thanks!

pierre2202 commented 1 week ago

no problem i did that, the exampleapp is uploaded with only the user_login_live.ex on http://localhost:4000/ when server is launched