dans.blog


The miscellaneous ramblings and thoughts of Dan G. Switzer, II

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

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.