disabled true doesn't allow to insert new records.

75 views
Skip to first unread message

mauro

unread,
Jun 16, 2011, 6:40:38 AM6/16/11
to SimpleForm
I have a numeric field with validates_numericality_of validation in
the model.
In the new action I have:

@model = Model.new(:num => Model.count + 1)

the field in the form has disabled => true, I don't want the user can
modify it.
When I call the form I see the correct value in the numeric field but
when I submit the form that value disappear and the error message is
that the value in num is not a number.
It works if I leave out disable => true.
How can solve it.

Carlos Antonio

unread,
Jun 16, 2011, 8:04:01 AM6/16/11
to plataformate...@googlegroups.com
This is a browser feature: it does not send disabled fields. If you don't want the user to edit the value, but still want it to be submitted, you can use the readonly attribute instead.

Anyway, I'd avoid accepting this :num attribute coming from the form if you don't want the user to change it. That's because a user can simply remove the disabled flag using the inspector or firebug, and submit another value, that you will be gladly accepting. Make sure you set the right value in the create action, or internally inside the model.

-- 
At.
Carlos A. da Silva

Mauro

unread,
Jun 16, 2011, 11:58:07 AM6/16/11
to plataformate...@googlegroups.com
On 16 June 2011 12:04, Carlos Antonio <carlosanto...@gmail.com> wrote:
> This is a browser feature: it does not send disabled fields. If you don't
> want the user to edit the value, but still want it to be submitted, you can
> use the readonly attribute instead.
> Anyway, I'd avoid accepting this :num attribute coming from the form if you
> don't want the user to change it. That's because a user can simply remove
> the disabled flag using the inspector or firebug, and submit another value,
> that you will be gladly accepting. Make sure you set the right value in the
> create action, or internally inside the model.

Yes that' s the solution, thank you very much.

Reply all
Reply to author
Forward
0 new messages