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: </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
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: </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 ![]()
3
Also Liked
sreyansjain
Last Post!
gilbertosj
Popular in Questions
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
I would like to know what is the best IDE for elixir development?
New
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
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
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
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
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
Hello, how can I check the Phoenix version ?
Thanks !
New
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
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
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
I would like to know what is the best IDE for elixir development?
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









