0
votes

My simple_forms are showing validation messages before the form is even submitted.

For example, right when you land on the signup page, it's as if you just tried submitting an empty form- the first_name and last_name fields are highlighted in red, with the can't be blank error messages next to them.

Adding:

required => true

(or false) on the simple_form has no effect.

I have validations in my user model. If I remove those model validations, the forms work as expected (adding required: true gives me properly-functioning client-side validation). However, I want to have both client-side and model validations.

Does anybody have a clue as to why validations are triggered when the form is first loaded?

I'm using simple_form 2.0.1 with bootstrap-sass 2.0.1 in my Rails 3.2.2 app. My user form uses the bootstrap styling ('form-horizontal'), although when I remove that it still validates prematurely. Also, adding :novalidate => true to the form builder has no effect.

Thanks!

Edit: here is the new action is my doctors_controller:

def new
    @doctor = Doctor.new
    @user = @doctor.build_user
end

(User is a polymorphic association and can belong to multiple models.)

It seems like the user model is getting saved even though I'm using build_user rather than create_user.

Solved

I updated my model validations to include on: save, which solved the problem. It was validating the not-yet-saved user object.

1
Can you post your controller actions?Tom L
add your solution as an answer, pleaseVasiliy Ermolovich

1 Answers

0
votes

I updated my model validations to include on: save, which solved the problem. It was validating the not-yet-saved user object.