0
votes

Using Rails 3.2.12 and simple_form 2.0.4

On our User model we have:

  validates_confirmation_of :email, :on => :create, :message => "should match confirmation"
  validates_confirmation_of :password, :message => "Your password confirmation does not match the password entered"

so far so good, however, if you have a confirmation error on either of these fields (ie they don't match) simple_form only marks the regular field with error classes and an error messages. My client wants the matching _confirmation field to be marked in the same red styling / error classes.

Is there a way to do this with simple_form without major re-engineering??

This is in my view: (similar for password)

<%= f.input :email_confirmation, :required => true, :label => "Verify Email Address", :input_html => {:rel => "tooltip", :title => "Please enter your email address again to prevent typing errors"} %>

thanks

1

1 Answers

0
votes

You could do it in a before_save( or before_create) and do a custom validation, and do a

before_create :email_validation

def email_validation
  if email validation stuff
    self.errors.add( :email, "error message")
    self.errors.add( :email_confirmation, "error message")
  end
end

this way you have better control on what kind of error messages you show too.