Add validation for custom fields in invitation form of devise_invitable
Asked Answered
S

0

7

As I know, devise has validation only for email and password, which can be reconfigurated in initializer devise.rb:

  # ==> Configuration for :validatable
  # Range for password length. Default is 6..128.
  # config.password_length = 6..128

  # Regex to use to validate the email address
  # config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i

How add validation for custom fields, which has been added into invitation form of devise_invitable?

For example, I need validation for the first_ and the last_ names in the form:

= simple_form_for resource, :as => resource_name, :url => invitation_path(resource_name) do |f|
  = f.input :first_name
  = f.input :last_name
  = f.input :email
  = f.button :submit

Thanks in advance!

Schliemann answered 24/7, 2011 at 17:32 Comment(1)
The solution is set config.validate_on_invite = true in initializers/devise.rbSchliemann

© 2022 - 2024 — McMap. All rights reserved.