Rails: Please enter an email address when email ends with space

From FVue
Jump to: navigation, search

Problem

When logging in via Firefox on Rails Devise form with an e-mail with trailing whitespace, the form gives error:

Please enter an email address.

Despite this setting in config/initializers/devise.rb:

config.strip_whitespace_keys = [:email]

Environment

  • rails-7
  • firefox-124
  • devise-4.9.2

Solution

Cause: The field in app/views/devise/sessions/new.html.erb is of type `email':

<input type="email" ...>

This causes Firefox to generate error message "Please enter an email address.".

Solution: Change the field type to type=text:

<input type="text" ...>

See also: https://stackoverflow.com/questions/59989950/why-html5-input-type-email-doesnt-allow-empty-space

Comments

blog comments powered by Disqus