Limiting the width of a field for integer data

510 views
Skip to first unread message

Bharat

unread,
Feb 26, 2011, 11:06:01 AM2/26/11
to SimpleForm
This may not be a limitation of Simple Form but rather Rails or HTML
forms or just lack of my knowledge.

I am trying to limit the number of integer characters that can be
entered for an integer valued field as shown below:

<%= form.input :instructor_access, :hint => "weeks", :input_html =>
{:maxlength => 2} %>
<%= form.input :course_access, :hint => "weeks", :size => 2 %>
<%= form.input :refund_period, :hint => "hours", :size => 3 %>
<%= form.input :refund_percent, :hint => "0 to 100", :size => 3 %>

I have tried various combinations but none seem to work. This is not
a problem for text/string type fields. Can this be done?

Thanks.

Bharat

Carlos Antonio da Silva

unread,
Feb 26, 2011, 8:56:11 PM2/26/11
to plataformate...@googlegroups.com, Bharat
I believe the :input_html => { :maxlength => XX } option should work properly.
SF does not do anything with maxlength in NumericFields, only set it for string fields and if it is not set.
--
At.
Carlos A. da Silva

Bharat

unread,
Feb 27, 2011, 8:46:10 AM2/27/11
to SimpleForm
Hello Carlos,
I tried it again. Does not work.
Thank you regardless.
Bharat

Carlos Antonio da Silva

unread,
Feb 27, 2011, 8:52:00 AM2/27/11
to plataformate...@googlegroups.com, Bharat
Weird.. which version of SF? Did you try with default Rails text / number fields?

Bharat

unread,
Feb 27, 2011, 10:58:27 AM2/27/11
to SimpleForm
Hello Carlos,
I am on Simple Form version 1.3.1 with Rails 3.0.3 and MRI 1.9.2 p0.
I am not sure if I understand what you mean by "Did you try with
default Rails text/number fields?"
Thanks.
Bharat

Carlos Antonio da Silva

unread,
Feb 27, 2011, 3:23:40 PM2/27/11
to plataformate...@googlegroups.com, Bharat
Bharat, I mean if you have tried using Rails form_for with text_field or number_field, setting the maxlength attribute, without using SimpleForm.
If that works, probably is something with SimpleForm, otherwise the issue might be in Rails itself.
Reply all
Reply to author
Forward
0 new messages