dev-rroslan

dev-rroslan

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

Showing Posts 1 to 4

polypush135

polypush135

First issue:

Your map has atoms for keys not string literals.
IE:
You sent

%{country_issued_id: “”}

it wants

%{"country_issued_id" => “”}

Because they are parameters are possibly coming in from outside and someone could possible run out of atoms causing their app to crash. Or put another way there would be no way to limit the number of atoms the system could possibly have to make if anyone can just submit the form and pass in a new key in the form of an atom. Thus why they warning you to use strings.

Also try to look up how to use the ` char in these posts to format your code sections. It will help others read it better.

The next warning is self explanatory. You are not using the thing thus either annotate it with a prefix of _or remote it

heres you issue.

{:ok,
assign(socket,
form: to_form(%{country_issued_id: “”})
)}

should look like

{:ok,
assign(socket,
form: to_form(%{"country_issued_id" => “”})
)}

Your to_form function is taking a map that has an atom.

At the end of the day these are just warnings.

dev-rroslan

dev-rroslan OP

I am getting error:
** (KeyError) key :country_issued_id not found in: %{“country_issued_id” => “”}

polypush135

polypush135

Do you know why its saying that?

its self explaining.
I don’t even have the full context and I can see from what you said that there is no atom key of :country_issued_id found inside of this map %{“country_issued_id” => “”}

So somewhere in your code is assuming this map will have a atom key of :country_issued_id thus you should fix that since its now a string.

Also maybe go read this https://arunramgt.medium.com/elixir-basics-of-atoms-9ff6c48463d6

I personally think its very important to have a fundamental understanding of atoms and strings. This is really at the core of your issue.

Hermanverschooten

Hermanverschooten

You are accessing :country_issued_id by way of @form.params.country_issued_id, that hash doesn’t have that key. You don’t even need that value-assignment, the field above handles that already. Look at how the code in CoreComponents.input extracts the value and assigns the key, so you don’t have to.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews