Blog News

Posts that are off topic. You can subscribe to these posts here

wordCounter jQuery Plugin now prevents further input

Written by: Peter Fisher on November 9, 2011
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

WordCounterAs requested by Irvin in a comment on the wordCounter documentation, I have updated the plugin to prevent further input if the limit is reached. Unfortunately the original implementation didn’t allow additional features to be included without a lot of re factoring.  So I decided to recode the plugin from scratch.

From the the git hub change log:

  • Total plugin rewrite
  • Separated limit checking logic into individual methods.
  • Added preventInput option which stops a further input (apart from the backspace) if the limit is reached.
  • Added more comments. Removed call to execute on window.load

The option to prevent further input must been included with the limit option.  If the limit is exceeded then a check for the preventInput setting is made.  If this is true then the  default event (IE updating the value) for the input is disabled.  This is done by the following:
[crayon lang=”javascript”]
e.preventDefault();
[/crayon]

The only input allowed is the backspace. In order to capture the keycodes a change to the type of event used to trigger the  wordCounter was required.  The plugin is now using the  keypress event rather then the keyup event.

As you can see by the changelog most of the plugin has been rewritten.

Please note, as this is such a major change I am classing this as beta version 0.1.0

More information can be found in the demo  page

I will update the sfWidgetWordCounter in the coming  evenings

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Peter Fisher is a web developer working in Gloucester UK. Founder of the digital agency Websomatic, author of this blog and the HowToCodeWell Youtube channel. Peter has over ten years of web development experience under his belt

Read all about Peter Fisher

Leave a Reply

Your email address will not be published. Required fields are marked *