0

Am using Rails3 and installed the latest jQuery plug-in. Am trying to get the char. count function working from this code below, but not having any success. Any help would be appreciated??

articles/_form.html.erb

<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>

<div class="field">
<%= f.label :body %><br />
<%= f.text_area :body id=testTextarea2 %>
</div>

<div class="field">
<%= f.label :tag_names, "Tags" %>  <br />
<%= f.text_field :tag_names %> 
</div>

layouts/application.html.erb

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <title>myblog.com</title>
   <%= stylesheet_link_tag 'scaffold' %>
   <%= stylesheet_link_tag 'screen', :media => 'screen' %>
   <%= stylesheet_link_tag 'print',  :media => 'print' %>
   <%= javascript_include_tag :defaults, "jquery.js", "counter.js", "rails.validations" %>
   <%= csrf_meta_tag %>
   <script src="/javascripts/jquery.textareaCounter.plugin.js" type="text/javascript"></script>


<script type="text/javascript">
var info;
$(document).ready(function()    {

       var options = {  
        'maxCharacterSize': -2,
        'originalStyle': 'originalTextareaInfo',
        'warningStyle' : 'warningTextareaInfo',
        'warningNumber': 40
        };
        $('#testTextarea').textareaCount(options);


       var options2 = {
        'maxCharacterSize': 200,
        'originalStyle': 'originalTextareaInfo',
        'warningStyle' : 'warningTextareaInfo',
        'warningNumber': 40,
        'displayFormat' : '#input/#max | #words words'
        };
        $('#testTextarea2').textareaCount(options2);


       var options3 = {
        'maxCharacterSize': 200,
        'originalStyle': 'originalTextareaInfo',
        'warningStyle' : 'warningTextareaInfo',
        'warningNumber': 40,
        'displayFormat' : '#left Characters Left / #max'
        };
        $('#testTextarea3').textareaCount(options3, function(data)

                    {
        $('#showData').html(data.input + " characters input. <br />" + data.left + " characters left. <br />" + data.max + " max characters. <br />" + data.words + " words input.");
            });
        });
</script>

SyntaxError in Articles#new

Showing /Users/blog/app/views/articles/_form.html.erb where line #23 raised:

compile error
/Users/blog/app/views/articles/_form.html.erb:23: syntax error, unexpected tIDENTIFIER,     expecting ')'
...append= ( f.text_area :body id="testTextarea2" );@output_buf...
                          ^
Extracted source (around line #23):

20: 
21:   <div class="field">
22:     <%= f.label :body %><br />
23:     <%= f.text_area :body id="testTextarea2" %>
24:   </div>
25:  
0

2 Answers 2

1
+50

The error you're seeing has nothing to do with jQuery or JS. The text_area helper expects a hash of attributes — this should rid you of the error:

f.text_area :body, :id => "testTextarea2"
Sign up to request clarification or add additional context in comments.

1 Comment

Cheers! (…öhhrm… the bounty seems to be still open.)
0

I would expect to see the following html being generated somewhere, where is it -- did you not show that code?

 <textarea id="testTextarea" cols="60" rows="10" ></textarea>
 <div class="originalTextareaInfo warningTextareaInfo">

 <textarea id="testTextarea2" cols="60" rows="10" ></textarea>
 <div class="originalTextareaInfo warningTextareaInfo">

 <textarea id="testTextarea3" cols="60" rows="10" ></textarea>
 <div class="originalTextareaInfo warningTextareaInfo">
 <div id="showData"></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.