As 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