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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
subsaharancoder
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
mohsen
I’m using an Umbrella project for a Phoenix application, and I want to have one Ecto Repo and one PostgreSQL database shared by all apps....
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews