diff --git a/assets/js/acf-price-v4.js b/assets/js/acf-price-v4.js index 42c3806..d3c9c19 100644 --- a/assets/js/acf-price-v4.js +++ b/assets/js/acf-price-v4.js @@ -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){ diff --git a/assets/js/acf-price-v5.js b/assets/js/acf-price-v5.js index 99a4942..d44aa54 100644 --- a/assets/js/acf-price-v5.js +++ b/assets/js/acf-price-v5.js @@ -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 ) { diff --git a/fields/acf-price-common.php b/fields/acf-price-common.php index 99ccc58..608a993 100644 --- a/fields/acf-price-common.php +++ b/fields/acf-price-common.php @@ -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'] ); @@ -59,4 +68,5 @@ public function format_value( $value, $post_id, $field ) return number_format( $value, $format['decimals'], $format['decimal_point'], $format['thousands_separator'] ); } + } \ No newline at end of file