I ran into the same issue recently, but instead of atom : string I had integer : string.
What I noticed was that the initial value is coming from the query, which is the value on the database, but if there are changes on the form the value will become an string since all params are strings coming from an HTML form
For example, you might have a field <.input type="float" field={@form[:my_float]>
The initial value if you render from the database would be a float like:
2.49
but if any changes are made to the form then the new value is the changed value, which is “2.49” (it will be converted again when saving).
A simple approach is to verify if any values matches, for example, in your case you could have
<% if @form[:role] in [:admin, "admin"], do: something() %>
you could also assign the value to a new assign and change the assign value in the validation handle_event to ensure you’ll always have an atom
it would be like
def handle_event("validate" params, socket) do
params_role = params["role"]
role = String.to_atom(params_role)
{:noreply,
socket
|> assing(:role, role)
}
end






















