Skip to content

Commit

Permalink
Fixed issue w/ currency symbol in custom amount input
Browse files Browse the repository at this point in the history
Also fixed issue with currency symbol after using format method within accounting.js
  • Loading branch information
devin committed Feb 26, 2016
1 parent 2291ab6 commit 5ae9a39
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
35 changes: 23 additions & 12 deletions assets/js/frontend/give-checkout-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,18 @@ jQuery( function ( $ ) {
*
* @description format the currency with accounting.js
* @param price
* @param args object
* @returns {*|string}
*/
function give_format_currency( price ) {
return accounting.formatMoney( price, {
symbol : give_global_vars.currency_sign,
decimal : give_global_vars.decimal_separator,
thousand : give_global_vars.thousands_separator,
precision: give_global_vars.number_decimals
} ).trim();
function give_format_currency( price, args ) {

//Properly position symbol after if selected
if ( give_global_vars.currency_pos == 'after' ) {
args.format = "%v%s";
}

return accounting.formatMoney( price, args ).trim();

}

/**
Expand Down Expand Up @@ -231,10 +234,16 @@ jQuery( function ( $ ) {
doc.on( 'blur', '.give-donation-amount .give-text-input', function ( e ) {

var pre_focus_amount = $( this ).data( 'amount' );

var value_now = give_unformat_currency( $( this ).val() );
var formatted_total = give_format_currency( value_now );
var format_args = {
symbol : '',
decimal : give_global_vars.decimal_separator,
thousand : give_global_vars.thousands_separator,
precision: give_global_vars.number_decimals
};
var formatted_total = give_format_currency( value_now, format_args );

//Set the custom amount input value formatted properly
$( this ).val( formatted_total );

//Does this number have a value?
Expand All @@ -245,8 +254,9 @@ jQuery( function ( $ ) {
//If values don't match up then proceed with updating donation total value
if ( pre_focus_amount !== value_now ) {

//update checkout total (include currency sign)
$( this ).parents( 'form' ).find( '.give-final-total-amount' ).data( 'total', value_now ).text( formatted_total );
//update donation total (include currency symbol)
format_args.symbol = give_global_vars.currency_sign;
$( this ).parents( 'form' ).find( '.give-final-total-amount' ).data( 'total', value_now ).text( give_format_currency( value_now, format_args ) );

//fade in/out updating text
$( this ).next( '.give-updating-price-loader' ).stop().fadeIn().fadeOut();
Expand All @@ -273,7 +283,8 @@ jQuery( function ( $ ) {
} );

/**
* Update Multiselect Vals
* Update Multiselect Values
*
* @description Helper function: Sets the multiselect amount values
*
* @param selected_field
Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/give-checkout-global.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5ae9a39

Please sign in to comment.