Search code examples
ruby-on-railsrubyprototypejs

textarea character count in Rails


I want to use observe_field to give me the character count of the textarea, updated as you type. What am I doing wrong here?

<div class="field">
  <%= observe_field :micropost_content,
      :function => "$('micropost_content').value.length" %>
  <%= f.text_area :content %>
</div>

Solution

  • If you don't set the frequency option it becomes event based (onchange.) Try:

    <%= observe_field :micropost_content, :frequency => 1,
          :function => "$('micropost_content').value.length" %>