jQuery-Knob icon indicating copy to clipboard operation
jQuery-Knob copied to clipboard

Update parse function to handle string with commas

Open cericthered opened this issue 9 years ago • 0 comments

If you are using a format function like the example below, it formats large numbers with commas ("1,000") to have a clean, readable format. However, the commas are not handled by the javascript parseFloat function in the way that is needed, so you end up parsing a number that does not match the original, and it will end up setting a new value on the dial which is incorrect. This happens when you manually type a value into the textbox. It will format the value and output, but it looks like that trigger another change event, which values the value to get validated/parsed again. I added a check in the 'parse' function to remove commas if the value is a string.

//EXAMPLE FORMAT FUNCTION THAT ADDS COMMA FOR THOUSANDS SEPARATORS 'format': function (val) { var formatted = addCommasToNumber(val); //for "1000", would return "1,000" return formatted; }

cericthered avatar Jan 29 '16 23:01 cericthered