I am given warning here:
warning: a map with atom keys was given to a form. Maps are always considered parameters and therefore must have string keys, got: %{country_issued_id: “”}
and another warning:
warning: variable “country_issued_id” is unused (if the variable is not meant to be used, prefix it with an underscore)
Below is my code, hope someone will help me:
defmodule UndiWeb.GenerateLive do
use UndiWeb, :live_view
alias Undi.Tokens.Token
alias Undi.Tokens
@impl true
def render(assigns) do
~H"“”
<.header>
Generate Token for login to survey
<:subtitle>From ID we will obtain your age and gender</:subtitle>
</.header>
<div>
<.simple_form for={@form} id="generate_link_form" phx-change="validate" phx-submit="save_token">
<.input
field={@form[:country_issued_id]}
value={@form.params.country_issued_id}
type="text"
label="MyKad"
/>
<:actions>
<.button phx-disable-with="Generating...">Generate Token</.button>
</:actions>
</.simple_form>
</div>
"""
end
@impl true
def mount(_params, _session, socket) do
{:ok,
assign(socket,
form: to_form(%{country_issued_id: “”})
)}
end
@impl true
def handle_event(“save_token”, %{“country_issued_id” => country_issued_id} = p, socket) do
case Tokens.create_token(p) do
{:ok, _token} →
{
:noreply,
socket
|> put_flash(:info, “Record created successfully”)
}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign_form(socket, changeset)}
end
end
@impl true
def handle_event(“validate”, _, socket) do
{:noreply, socket}
end
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
assign(socket, :form, to_form(changeset))
end
end