gilbertosj

gilbertosj

Getting value from an input (liveview)

I am currently starting to use “liveview” in my app, but I have a problem getting the value of a form entry.
I can’t find the reason why I can’t.
Could you help me identify where the problem is?

Liveview

defmodule MyappWeb.LiveRequest do
    use Phoenix.LiveView
  
    def render(assigns) do
      ~L"""

      <h1 id="myHeader"><%= @deploy_step %></h1>
                
      <div class="input-group input-group-sm">
          <label>Domínio:&nbsp;&nbsp;</label>
          <input type="text" name="params" list="matches" placeholder="Domínio..." class="form-control">
            <span class="input-group-append">
              <button phx-click="checkdomain" type="button" class="btn btn-info btn-flat">Checar Domínio!</button>
            </span>
      </div>
      """
    end
 
    def mount(_session, socket) do
        {:ok, assign(socket, params: nil, deploy_step: "Aguardando para busca!")}
    end

      def handle_event(checkdomain", %{"params" => params}, socket) do
        url = "https://myapi.com/v2/test/list/full/#{params}"
        response = HTTPoison.get!(url)    
        registrobr = response.body |> Poison.decode!()
        status = registrobr["fqdn"]

        {:noreply, assign(socket, params: params, deploy_step: status)}
      end

  end

Always returns me null

Marked As Solved

chrismccord

chrismccord

Creator of Phoenix

as sreyansjain said, you need to use a form with phx-submit, for example:

    def render(assigns) do
      ~L"""

      <h1 id="myHeader"><%= @deploy_step %></h1>
                
      <div class="input-group input-group-sm">
        <form phx-submit="checkdomain">
          <label>Domínio:&nbsp;&nbsp;</label>
          <input type="text" name="params" list="matches" placeholder="Domínio..." class="form-control">
          <span class="input-group-append">
            <button type="submit" class="btn btn-info btn-flat">Checar Domínio!</button>
          </span>
        </form>
      </div>
      """
    end

note, I also changed the button to type="submit". Cheers :slight_smile:

Also Liked

sreyansjain

sreyansjain

Input needs to be in the form tag and you need to use phx-submit event

Last Post!

gilbertosj

gilbertosj

It really was that.
Thank you very much

Where Next?

Popular in Questions Top

New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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 records...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement