ryanzidago

ryanzidago

I have the following form:

<%= form_for @conn, Routes.auth_path(@conn, :request, "passwordless"), [method: :get], fn f -> %>
<%= hidden_input f, :redirect_url, value: Routes.page_path(@conn, :login_mail_sent) %>
<%= email_input f, :email, placeholder: "Your email address", required: :true %>
<%= submit "Log in" %>
<% end %>

Now if I try to submit the form with the email field input empty, I’ll get a small error bubble from Phoenix with something saying: “Please, fill out this field.”

Could anyone please tell me how can I translate this error message?

I know I can use gettext but I do not understand where should I call the gettext function since the string “Please fill out this field” is not written anywhere in the code.

Showing Posts 1 to 10

sfusato

sfusato

That bubble message you get is not from Phoenix, but from your browser (if you remove required: :true, you will get Phoenix’s message which is can't be blank)

For the Phoenix error messages, check priv/gettext/errors.pot

ryanzidago

ryanzidago OP

@sfusato thanks for the info!

I decided to change the default browser message thanks to this stackoverflow post.

sfusato

sfusato

oninvalid only seems to have ~38% global coverage according to caniuse.com

dimitarvp

dimitarvp

You’re better off simply providing a translated title attribute for the element. Much simpler and works well.

ryanzidago

ryanzidago OP

What do you mean exactly?

If I write:

<%= email_input f, :email, placeholder: "Your email address", required: :true, title: "Veuillez fournir votre adresse Mail" %>

It still displays the English warning “Please fill out this form”.

dimitarvp

dimitarvp

It shouldn’t say that at all, I guess you have a validation form error raised earlier than before the browser can yell at you for an invalid email field.

ryanzidago

ryanzidago OP

When I remove the required: :true option, I don’t get the can't be blank message that @sfusato mentionend; hence why I decided to write some small javascript.

That might be the reason why also the title property does not work?

Also this form is not used to create a user, it is mostly for login so it has nothing to do with Ecto (who, as far as I know, usually displays those error this field can't be blank type of message).

dimitarvp

dimitarvp

Very likely. For title to work you need not to intercept and process JS events for the element in question.

If that’s not okay then I am afraid you’ll have to go all the way with JS.

sfusato

sfusato

Do you have :email in the validate_required([:email]) changeset function?

You can still use Changesets even without a schema: check Schemaless Changesets

ryanzidago

ryanzidago OP

No actually I do not use a changeset at all, just the @conn.

I’ll look into how to implement a schema less changeset.
Thanks for the tip one again.

— 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
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
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
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

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
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews