Skip to content

Commit

Permalink
Merge pull request #3377 from WordImpress/issues/3299
Browse files Browse the repository at this point in the history
fix(donation): getting Give notices when changing the Donation level #3299
  • Loading branch information
ravinderk committed Jun 18, 2018
2 parents 98350a0 + df04be2 commit 36cdc26
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
23 changes: 19 additions & 4 deletions assets/src/js/frontend/give-donations.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ Give.form = {
}

// Is this a custom amount selection?
if ( 'custom' === level_amount ) {
if ( 'custom' === level_price_id ) {
// It is, so focus on the custom amount input.
$form.find( '.give-amount-top' ).val( '' ).focus();
return false; // Bounce out
Expand Down Expand Up @@ -706,9 +706,6 @@ Give.form = {
// (c) donation amount
$form.find( '.give-donation-amount .give-text-input' )
.trigger( 'blur', [ $form, level_amount, level_price_id ] );

// trigger an event for hooks
jQuery( document ).trigger( 'give_donation_value_updated', [ $form, level_amount, level_price_id ] );
},

/**
Expand Down Expand Up @@ -802,6 +799,7 @@ Give.form = {
price_id = this.getPriceID( $form, true );

// Don't allow zero donation amounts.
// https://github.com/WordImpress/Give/issues/3181
if( 0 === amount ) {
return false
}
Expand Down Expand Up @@ -1128,6 +1126,20 @@ jQuery( function( $ ) {

price_id = 'undefined' === typeof price_id ? Give.form.fn.getPriceID( parent_form, true ) : price_id;

// https://github.com/WordImpress/Give/issues/3299
// If we change from custom amount to donation level then
// this event fire twice. First on amount field blur and second time on level button/radio/select click which cause of minimum donation notice.
// This condition will prevent minimum donation amount notice show by set default level.
if( '' === value_now || 0 === value_now ) {
let $default_level = $( '.give-donation-levels-wrap [data-default="1"]', $parent_form );

if( $default_level.length ) {
price_id = $default_level.data('price-id');
this_value = value_now = Give.fn.unFormatCurrency( $default_level.val(), decimal_separator );
formatted_total = Give.form.fn.formatAmount( value_now, parent_form, {} );
}
}

// Cache donor selected price id for a amount.
Give.fn.setCache( 'amount_' + value_now, price_id, parent_form );
$( this ).val( formatted_total );
Expand Down Expand Up @@ -1208,6 +1220,9 @@ jQuery( function( $ ) {
$( this ).parent( '.give-donation-amount' )
.removeClass( 'give-custom-amount-focus-in' );

// trigger an event for hooks
jQuery( document ).trigger( 'give_donation_value_updated', [ parent_form, value_now, price_id ] );

} );

// Multi-level Buttons: Update Amount Field based on Multi-level Donation Select
Expand Down
9 changes: 6 additions & 3 deletions includes/forms/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,11 @@ function give_output_levels( $form_id ) {
) );

$output .= sprintf(
'<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s">%4$s</button></li>',
'<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s" data-default="%4$s">%5$s</button></li>',
$price['_give_id']['level_id'],
$level_classes,
$formatted_amount,
array_key_exists( '_give_default', $price ) ? 1 : 0,
$level_text
);
}
Expand Down Expand Up @@ -553,11 +554,12 @@ function give_output_levels( $form_id ) {
) );

$output .= sprintf(
'<li><input type="radio" data-price-id="%1$s" class="%2$s" value="%3$s" name="give-radio-donation-level" id="give-radio-level-%1$s" %4$s ><label for="give-radio-level-%1$s">%5$s</label></li>',
'<li><input type="radio" data-price-id="%1$s" class="%2$s" value="%3$s" name="give-radio-donation-level" id="give-radio-level-%1$s" %4$s data-default="%5$s"><label for="give-radio-level-%1$s">%6$s</label></li>',
$price['_give_id']['level_id'],
$level_classes,
$formatted_amount,
( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ),
array_key_exists( '_give_default', $price ) ? 1 : 0,
$level_text
);
}
Expand Down Expand Up @@ -593,11 +595,12 @@ function give_output_levels( $form_id ) {
) );

$output .= sprintf(
'<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s >%5$s</option>',
'<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s data-default="%5$s">%6$s</option>',
$price['_give_id']['level_id'],
$level_classes,
$formatted_amount,
( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ),
array_key_exists( '_give_default', $price ) ? 1 : 0,
$level_text
);
}
Expand Down

0 comments on commit 36cdc26

Please sign in to comment.