views:

2353

answers:

2

I tried applying the :maxlenght => 40 on a textarea on my form. But it didn't work out. Can we have a length limit on a textarea?

The code for text area is

<%= f.text_area :data,
                :rows => 2,
                :cols => 60 ,
                :maxlength => 140,
                :autocomplete => :off,
                :class => "textareabytes" %>
+3  A: 

Could it be due to a typo?

":maxlenght => 40 " in your post is misspelt.

EDIT:

I didn't read your post carefully. I think there is no maxlength attribute for textarea in HTML. You will have to handle it in JavaScript. There is more information in "MaxLength on a Textarea".

Rahul
Im sorry actually Its correct in the code i spelt it wrong here
Please see to the edited question
Thnx buddysince no other go .....i wrote a javascript function to implement this....
+4  A: 

Just like Rahul said, there's no maxlength attribute for textarea in HTML. Only text input's have that.

The thing you need to remember, is that RoR's text_area function (and all of RoR's HTML-generator functions) accept any argument you'll give them. If they don't recognized the parameter, then the'll just convert it to HTML.

<%=f.text_area :data, :hellothere => "hello to you too"%>

Will output this HTML:

<textarea name="data" hellothere="hello to you too"></textarea>

I know it's hard to remember, but Ruby on Rails isn't magic, it just does a lot of things for you. The trick is to know how it does them, so you can understand why they work, and how to fix them when they don't!

scraimer