Author: Robert Knothe

Contact: bob{@}decorplanit.com (remove brackets)

Web site: http://www.decorplanit.com/plugin/ complete with detailed examples and option/html 5 data code generator/

github: https://github.com/BobKnothe/autoNumeric

jQuery: http://plugins.jquery.com/autoNumeric/

autoNumeric 1.9.26 is a jQuery plugin that automatically formats currency and numbers as you type on form inputs. It supports most International numeric formats and currency signs including those used in Europe, North and South America, Asia and India (lakhs**).

Any number of currency formats can reside on the same page and are configured by options that can be placed as HTML5 data attribute or passed as an argument. These settings can easily be changed at any time using the new ‘update’ method or via the callback feature.

Seven built in methods and fifteen options gives you the flexibility needed to use autoNumeric to its maximum potential (details below).

Examples of autoNumeric's flexibility:

Demonstrates some of the available decimal & thousand separators
decimal '.' & thousand ',' separators decimal ',' & thousand '.' separators decimal '.' & thousand ' ' separators
     
Demonstrates use of currency signs and the placement
Dollar as a prefix Euro as prefix Swiss Franc as a suffix
     
Demonstrates min/max values including negative values with brackets on focus out.
0 to 9999 no decimal place -99.99 to 1000.00 two decimal places -9999.99 to 0.00 negative only w/brackets
     
Demonstrates digital grouping "hint - for none set the thousand seperator (aSep: "" or data-a-sep="") to and empty string
none 2 India's lakhs ( on values below 1 billion) 4 used in some Asian countries
     
Demonstrates non-input elements - default values are formatted on page ready - can changed via the "set" method
<span class="auto">1234.56</span> <td class="auto">1234.56</td> <label class="auto">1234.56</label>
1234.56 1234.56

Key features and general notes:

Elements supported:

Default settings, options and HTML 5 data:

Callback function:

Defaults values on autoNumeric controlled elements:

Precision control of minimum & maximum values:

Currency signs:


Default settings & options - for a detailed info please see http://www.decorplanit.com/plugin/


Method(s) Description Format
  'init' initializes autoNumeric $(selector).autoNumeric('init', {options});
  'destroy' disables autoNumeric for the selected element $(selector).autoNumeric('destroy');
  'update' updates options - can be called multiple times $(selector).autoNumeric('update', {options});
  'set' returns a formatted string via ".val()" or ".text' $(selector).autoNumeric('set', value);
  'get' returns un-formatted object via ".val()" or ".text()" $(selector).autoNumeric('get');
  'getString' returns a string 'URL encoded' from the selected form $(selector).autoNumeric('getString');
  'getArray' returns a array of objects from the selected form $(selector).autoNumeric('getArray');
  'getSettings' returns settings for the selected element $(selector).autoNumeric('getSettings');

'init' method - initializes autoNumeric and must be run before other methods can be called.

Note the following:

Warning

Calling the "init" method on a element where the decimal point "aDec" and the thousand separator "aSep" are equal will cause an error message to be thrown to the javascript console.

Calling the 'init' methods on a element that is not supported by autoNumeric will cause an error message to be thrown to the javascript console.


'destroy' method - removes autoNumeric from the selected element(s).

Note the following:


"update' method - easily update element(s) that have been previously initialized 'init' by autoNumeric.

Note the following:

Warning

Calling the 'update' method prior to the 'init' method will cause a error message to be thrown to the Javascript console.

Calling the "update" method on a element where the decimal point "aDec" and the thousand separator "aSep" are equal will cause an error message to be thrown to the javascript console.

Calling the 'update' method on a element that is not supported by autoNumeric will cause an error message to be thrown to the javascript console.


'set' method - The 'set' method allows you to easily format numbers and numeric strings

Proper format for the 'set' method.

Note the following:

Calling the 'set' method prior to the 'init' method will cause a error message to be thrown to the Javascript console.

Calling the 'set' method on a element that is not supported by autoNumeric will cause an error message to be thrown to the javascript console.


'get' method - The 'get' method allows you to easily remove the formating from a string on a autoNumeric controlled element and returns a string.

Proper format for the 'get' method.

Note the following:

Warning

Calling the 'get' method prior to the 'init' method will cause a error message to be thrown to the Javascript console.

Calling the 'get' method on a element that is not supported by autoNumeric will cause an error message to be thrown to the javascript console.


'getString' method - this basically uses jQuery's .serialize() method which creates a text string (URL-encoded notation) from a set of form elements that is ready for submission. The extra step taken here is the string is split and iterated through and the formatted values are replaced with unformatted values. The string is then joined back together and returned.

Proper format for the 'getString' method.

Note the following:

Warning

At least one input must be controled by autoNumeric. If not the 'getSting' method will cause a error message to be thrown the the Javascript console.


'getArray' method - this basically uses jQuery's .serializeArray() method which returns a Javascript array of objects, ready to be encoded as a JSON string. The extra step taken here is the the object array is iterated through and formatted values are replaced with un-formatted values and returned.

Proper format for the 'getArray' method.

Note the following:

Warning

At least one input must be controled by autoNumeric. If not the 'getArray' method will cause a error message to be thrown the the Javascript console.


'getSettings' method - this returns an object that shows the autoNumeric settings for the field. You may find this helpful when developing a page.

Proper format for the 'getArray' method.

Note the following:

Warning

Calling the 'getSettings' method prior to the 'init' will cause a error message to be thrown the the Javascript console.

 


Complete documentation and examples can be found at http://www.decorplanit.com/plugin/

Need a custom modification? Cantact me at bob{@}decorplanit.com or github.

Enjoy