HcpShadow / jquery-numberformatter

Automatically exported from code.google.com/p/jquery-numberformatter
0 stars 0 forks source link

Formatting breaks after first iteration #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Select a group of elements to format
2. Observe that the format is correctly applied to the first match
3. Observe that it's not for the subsequent matches.

Example:

<table>
<tr><td class="money">2.5</td></tr>
<tr><td class="money">2.5</td></tr>
<tr><td class="money">2.5</td></tr>
<tr><td class="money">2.5</td></tr>
</table>

<script type="text/javascript">
jQuery('td.money').format({format:'$#,###.00',locale:'us'});
</script>

Expected output:

$2.50
$2.50
$2.50
$2.50

Actual output:

$2.50
2.50
2.50
2.50

(Note that part of the format works, but the $ part is lost after the first
value).

Original issue reported on code.google.com by jamesgur...@gmail.com on 11 Feb 2010 at 7:19

GoogleCodeExporter commented 8 years ago
I've done some investigation, and the reason this is happening is because the 
prefix
and suffix are determined for each() item in the list. However, during the first
iteration, they're stripped from the options.format, which means that on the 
second
loop, the prefix and suffix are lost.

Simply moving the code which determines the prefix/suffix outside the loop 
solves the
problem. I've attached a diff.

Original comment by jamesgur...@gmail.com on 11 Feb 2010 at 7:37

Attachments:

GoogleCodeExporter commented 8 years ago
Fixed for upcoming 1.2 (available on svn atm as beta).

Appears to now work fine, also thanks james for the diff.

Original comment by apar...@gmail.com on 29 Apr 2010 at 4:58