PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Change the character limit wording

  1. How can I change the character limit wording?

    I am using WP in other language so "0 of 2000 max characters" doesn't look good. I'd rather prefer something like "0/200".

    Thanks

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  2. Gravity Forms uses this script to count characters in a textarea:

    http://roy-jin.appspot.com/jsp/textareaCounter.jsp

    Looking at those docs, it seems like you want to use displayFormat. Your display format would look something like this:

    [js]
    $jQuery(document).ready(function(){
    	var options = {
    		'displayFormat' : '#input / #max'
    	};
    	$('#yourtextareaID').textareaCount(options);
    });

    You will be adding JavaScript to the head of the page that contains the form with your textarea:
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  3. Thank you, Chris!

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  4. Ah, it alsmost worked.

    It displays as:

    3 of 2000 max characters
    3 / #max

    Now. So the previous text is still present and also maximum number of characters is not displayed properly.

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  5. Do you have a link to your page? It's possible that this script is being included before Gravity Forms includes their script, so theirs runs later?

    I think #max not working is because of the same thing. The #max shorthand will only work when maxCharacterSize is defined (by default it's -1), and my guess is that the limit is coming from Gravity Forms later. Please post a URL to your page, or see if the order of the scripts might be fouling things.

    Posted 13 years ago on Sunday August 28, 2011 | Permalink
  6. I can't provide the link right now as I am doing it on local server.
    I checked the order of scripts in head through firebug, and the script you provided is the last one, just before the closing </head>.

    I tried putting it earlier, just after <?php wp_head(); ?>, but with the same result.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  7. While reading the documentation today, I found a hook we should be using instead: gform_counter_script

    http://www.gravityhelp.com/documentation/page/Gform_counter_script

    Try this in your functions.php

    [php]
    // change the 6 here to your form ID
    add_filter("gform_counter_script_6", "set_counter_script", 10, 4);
    function set_counter_script($script, $form_id, $field_id, $max_length){
        $script = "<script type='text/javascript'>//<![CDATA[\n jQuery(document).ready(function(){" .
                    "jQuery('#{$field_id}').textareaCount(" .
                    "    {" .
                    "    'maxCharacterSize': {$max_length}," .
                    "    'originalStyle': 'ginput_counter'," .
                    "    'displayFormat' : '#input / #max'" .
                    "    })});" .
                  "\n//]]></script>";
        return $script;
    }
    ?>

    Sorry about that.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  8. it works great, thanks!

    Is there a simple way to make this global? So when I add new forms they look the same?

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  9. Yes, just remove the "_6" from the "gform_counter_script_6" - that will apply it to all forms, not just form 6. The 6 is your form ID. Most of the Gravity Forms hooks and filters work in the same manner (global or form-specific.)

    Make the second line look like this:

    add_filter("gform_counter_script", "set_counter_script", 10, 4);
    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  10. That worked perfectly.
    Another great solution from GF support!
    Thank you.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  11. Awesome, glad you got that working.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink

This topic has been resolved and has been closed to new replies.