Commit 5e2f5b23 authored by Kevin Stover's avatar Kevin Stover Committed by Kyle B. Johnson

Changing the way that we handle currency formatting by adding a...

Changing the way that we handle currency formatting by adding a renderCurrencyFormatting() helper method. This should handle non-English currency separators as well. Closes #1904. (#2185)
parent 0ba8c441
......@@ -105,8 +105,6 @@ define([], function() {
}
this.totalModel.set( 'value', newTotal.toFixed( 2 ) );
// this.totalModel.set( 'reRender', true );
// this.totalModel.set( 'reRender', false );
this.totalModel.trigger( 'reRender' );
}
});
......
......@@ -188,9 +188,20 @@ define( [], function() {
}
},
currencySymbol: function() {
renderCurrencyFormatting: function( number ) {
/*
* Our number will have a . as a decimal point. We want to replace that with our locale decimal, nfi18n.decimal_point.
*/
var replacedDecimal = number.toString().replace( '.', '||' );
/*
* Add thousands separator. Our original number var won't have thousands separators.
*/
var replacedThousands = replacedDecimal.replace( /\B(?=(\d{3})+(?!\d))/g, nfi18n.thousands_sep );
var formattedNumber = replacedThousands.replace( '||', nfi18n.decimal_point );
var form = nfRadio.channel( 'app' ).request( 'get:form', that.model.get( 'formID' ) );
return form.get( 'settings' ).currency_symbol;
var currency_symbol = form.get( 'settings' ).currency_symbol;
return currency_symbol + formattedNumber;
}
};
},
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php if ( ! defined( 'ABSPATH' ) ) exit;
global $wp_locale;
return apply_filters( 'ninja_forms_i18n_front_end', array(
'ninjaForms' => __( 'Ninja Forms', 'ninja-forms' ),
'changeEmailErrorMsg' => __( 'Please enter a valid email address!', 'ninja-forms' ),
'confirmFieldErrorMsg' => __( 'These fields must match!', 'ninja-forms' ),
'fieldNumberNumMinError' => __( 'Number Min Error', 'ninja-forms' ),
'fieldNumberNumMaxError' => __( 'Number Max Error', 'ninja-forms' ),
'fieldNumberIncrementBy' => __( 'Please increment by ', 'ninja-forms' ),
'fieldTextareaRTEInsertLink' => __( 'Insert Link', 'ninja-forms' ),
'fieldTextareaRTEInsertMedia' => __( 'Insert Media', 'ninja-forms' ),
'fieldTextareaRTESelectAFile' => __( 'Select a file', 'ninja-forms' ),
'formErrorsCorrectErrors' => __( 'Please correct errors before submitting this form.', 'ninja-forms' ),
'validateRequiredField' => __( 'This is a required field.', 'ninja-forms' ),
'honeypotHoneypotError' => __( 'Honeypot Error', 'ninja-forms' ),
'ninjaForms' => __( 'Ninja Forms', 'ninja-forms' ),
'changeEmailErrorMsg' => __( 'Please enter a valid email address!', 'ninja-forms' ),
'confirmFieldErrorMsg' => __( 'These fields must match!', 'ninja-forms' ),
'fieldNumberNumMinError' => __( 'Number Min Error', 'ninja-forms' ),
'fieldNumberNumMaxError' => __( 'Number Max Error', 'ninja-forms' ),
'fieldNumberIncrementBy' => __( 'Please increment by ', 'ninja-forms' ),
'fieldTextareaRTEInsertLink' => __( 'Insert Link', 'ninja-forms' ),
'fieldTextareaRTEInsertMedia' => __( 'Insert Media', 'ninja-forms' ),
'fieldTextareaRTESelectAFile' => __( 'Select a file', 'ninja-forms' ),
'formErrorsCorrectErrors' => __( 'Please correct errors before submitting this form.', 'ninja-forms' ),
'validateRequiredField' => __( 'This is a required field.', 'ninja-forms' ),
'honeypotHoneypotError' => __( 'Honeypot Error', 'ninja-forms' ),
'fileUploadOldCodeFileUploadInProgress' => __( 'File Upload in Progress.', 'ninja-forms' ),
'fileUploadOldCodeFileUpload' => __( 'FILE UPLOAD', 'ninja-forms' ),
'currencySymbol' => Ninja_Forms()->get_setting( 'currency_symbol' ),
'fieldsMarkedRequired' => sprintf( __( 'Fields marked with an %s*%s are required', 'ninja-forms' ), '<span class="ninja-forms-req-symbol">', '</span>' )
'fileUploadOldCodeFileUpload' => __( 'FILE UPLOAD', 'ninja-forms' ),
'currencySymbol' => Ninja_Forms()->get_setting( 'currency_symbol' ),
'fieldsMarkedRequired' => sprintf( __( 'Fields marked with an %s*%s are required', 'ninja-forms' ), '<span class="ninja-forms-req-symbol">', '</span>' ),
'thousands_sep' => $wp_locale->number_format[ 'thousands_sep' ],
'decimal_point' => $wp_locale->number_format[ 'decimal_point' ],
));
......@@ -37,6 +37,8 @@ final class NF_Display_Render
public static function localize( $form_id )
{
global $wp_locale;
$capability = apply_filters( 'ninja_forms_display_test_values_capabilities', 'read' );
if( isset( $_GET[ 'ninja_forms_test_values' ] ) && current_user_can( $capability ) ){
self::$use_test_values = TRUE;
......@@ -253,15 +255,25 @@ final class NF_Display_Render
}
}
$thousands_sep = $wp_locale->number_format[ 'thousands_sep'];
$decimal_point = $wp_locale->number_format[ 'decimal_point' ];
// TODO: Find a better way to do this.
if ('shipping' == $settings['type']) {
$settings['shipping_cost'] = preg_replace ('/[^\d,\.]/', '', $settings['shipping_cost']);
$settings['shipping_cost'] = str_replace( Ninja_Forms()->get_setting( 'currency_symbol' ), '', $settings['shipping_cost']);
$settings['shipping_cost'] = number_format($settings['shipping_cost'], 2);
$settings[ 'shipping_cost' ] = preg_replace ('/[^\d,\.]/', '', $settings[ 'shipping_cost' ] );
$settings[ 'shipping_cost' ] = str_replace( Ninja_Forms()->get_setting( 'currency_symbol' ), '', $settings[ 'shipping_cost' ] );
$settings[ 'shipping_cost' ] = str_replace( $decimal_point, '||', $settings[ 'shipping_cost' ] );
$settings[ 'shipping_cost' ] = str_replace( $thousands_sep, '', $settings[ 'shipping_cost' ] );
$settings[ 'shipping_cost' ] = str_replace( '||', '.', $settings[ 'shipping_cost' ] );
} elseif ('product' == $settings['type']) {
$settings['product_price'] = preg_replace ('/[^\d,\.]/', '', $settings[ 'product_price' ] );
$settings['product_price'] = str_replace( Ninja_Forms()->get_setting( 'currency_symbol' ), '', $settings['product_price']);
$settings['product_price'] = number_format($settings['product_price'], 2);
$settings[ 'product_price' ] = str_replace( $decimal_point, '||', $settings[ 'product_price' ] );
$settings[ 'product_price' ] = str_replace( $thousands_sep, '', $settings[ 'product_price' ] );
$settings[ 'product_price' ] = str_replace( '||', '.', $settings[ 'product_price' ] );
} elseif ('total' == $settings['type'] && isset($settings['value'])) {
$settings['value'] = number_format($settings['value'], 2);
}
......@@ -498,6 +510,7 @@ final class NF_Display_Render
public static function enqueue_scripts( $form_id, $is_preview = false )
{
global $wp_locale;
$form = Ninja_Forms()->form( $form_id )->get();
$ver = Ninja_Forms::VERSION;
......
......@@ -6,7 +6,7 @@
<script id="tmpl-nf-product-single" type="text/template">
<span class="nf-product-price-label">{{{ nfi18n.fieldsProductsPrice }}}</span>
<span class="nf-product-price">{{{ data.currencySymbol() }}}{{{ data.product_price }}}</span>
<span class="nf-product-price">{{{ data.renderCurrencyFormatting( data.product_price ) }}}</span>
{{{ data.renderProductQuantity() }}}
</script>
......
<script id="tmpl-nf-field-shipping" type="text/template">
<span id="nf-field-{{{ data.id }}}" name="nf-field-{{{ data.id }}}" class="nf-static {{{ data.renderClasses() }}} nf-element">{{{ data.currencySymbol() }}} {{{ data.shipping_cost }}}</span>
<span id="nf-field-{{{ data.id }}}" name="nf-field-{{{ data.id }}}" class="nf-static {{{ data.renderClasses() }}} nf-element">{{{ data.renderCurrencyFormatting( data.shipping_cost ) }}}</span>
</script>
<script id="tmpl-nf-field-total" type="text/template">
<span id="nf-field-{{{ data.id }}}" name="nf-field-{{{ data.id }}}" class="nf-static {{{ data.renderClasses() }}} nf-element">{{{ data.currencySymbol() }}}{{{ data.value }}}</span>
<span id="nf-field-{{{ data.id }}}" name="nf-field-{{{ data.id }}}" class="nf-static {{{ data.renderClasses() }}} nf-element">{{{ data.renderCurrencyFormatting( data.value ) }}}</span>
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment