jQuery Calculation Plug-in v0.3 released...

Categories: jQuery

I've updated the jQuery Calculation Plug-in with a few changes:

  • Refactored the aggregate methods (since they all use the same core logic) to use the $.extend() method
  • Added support for negative numbers in the regex (now uses /-?\d+(,\d{3})*(\.\d{1,})?/g)
  • Added min/max aggregate methods
  • Added defaults.onParseError and defaults.onParseClear methods to add logic for parsing errors

The onParseError/onParseClear methods are useful when you need to flag the element that threw the error—such as changing the background color of the element to highlight it doesn't contain a valid number.

Make sure to check out the example of the avg() method on the documentation page. If you input an alpha string into any of the fields, the field will turn red to indicate the parsing engine could not find a number in the field.

I also added support for negative numbers—which was an oversight on my part.

Related Blog Entries

Comments

Rey Bango's Gravatar Great work Dan!
Dan G. Switzer, II's Gravatar @Rey:

Thanks!
Fontzter's Gravatar Thanks Dan!
Fontzter's Gravatar Hey Dan,

I had a need to use parenthesis to indicate negative numbers in an app. To still use the calc plugin, I added a replace to the parseNumber function so that the parenthesis would be replaced with a minus sign. This seems to do the trick. Just thought I would mention it to you.

v=$el[sMethod]().replace('(','-').replace(')','').match(defaults.reNumbers,"");

Thanks,
Dave

Add Comment



If you subscribe, any new posts to this thread will be sent to your email address.