Skip to content

Commit

Permalink
Number format should not happen during parsing, but only on display. F…
Browse files Browse the repository at this point in the history
…ixes speccode#11
  • Loading branch information
Benjamin Pick committed Oct 26, 2018
1 parent be2bff8 commit 7ac34d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion assets/js/acf-price-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

function initialize_field( $el ) {
var $input = $el.find('input');
$input.number( true, $input.data('format-decimals'), $input.data('format-decimal_point'), $input.data('format-thousands_separator') );
var val = $input.val();
$input.number(true, $input.data('format-decimals'), $input.data('format-decimal_point'), $input.data('format-thousands_separator') );
$input.val(val);
}

$(document).on('acf/setup_fields', function(e, postbox){
Expand Down
4 changes: 3 additions & 1 deletion assets/js/acf-price-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

function initialize_field( $el ) {
var $input = $el.find('input');
$input.number( true, $input.data('format-decimals'), $input.data('format-decimal_point'), $input.data('format-thousands_separator') );
var val = $input.val();
$input.number(true, $input.data('format-decimals'), $input.data('format-decimal_point'), $input.data('format-thousands_separator') );
$input.val(val);
}

acf.add_action('ready append', function( $el ) {
Expand Down
10 changes: 10 additions & 0 deletions fields/acf-price-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public function update_value( $value, $post_id, $field )
return $value;
}

public function load_value( $value, $post_id, $field )
{
if ( empty( $value ) ) {
$value = 0;
}

return $value;
}

public function format_value( $value, $post_id, $field )
{
$format = $this->parse_format( $field['format'] );
Expand All @@ -59,4 +68,5 @@ public function format_value( $value, $post_id, $field )

return number_format( $value, $format['decimals'], $format['decimal_point'], $format['thousands_separator'] );
}

}

0 comments on commit 7ac34d8

Please sign in to comment.