From 31f80913b166a3a98a7bf2b593d7d2636552883d Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Sun, 15 Jan 2017 05:58:21 -0500 Subject: [PATCH 1/4] =?UTF-8?q?Don=E2=80=99t=20erase=20payment=20details?= =?UTF-8?q?=20w/=20=E2=80=98update=5Fcheckout=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/frontend/checkout.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index 1c27db739f6..d6500a53f9e 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -290,6 +290,20 @@ jQuery( function( $ ) { var termsCheckBoxChecked = $( '#terms' ).prop( 'checked' ); + // Save payment details to a temporary object + var paymentDetails = {}; + $( '.payment_box input' ).each( function() { + var ID = $( this ).attr( 'id' ); + + if ( ID ) { + if ( 'checkbox' === $( this ).attr( 'type' ) ) { + paymentDetails[ ID ] = $( this ).prop( 'checked' ); + } else { + paymentDetails[ ID ] = $( this ).val(); + } + } + }); + // Always update the fragments if ( data && data.fragments ) { $.each( data.fragments, function ( key, value ) { @@ -303,6 +317,21 @@ jQuery( function( $ ) { $( '#terms' ).prop( 'checked', true ); } + // Fill in the payment details if possible + if ( ! $.isEmptyObject( paymentDetails ) ) { + $( '.payment_box input' ).each( function() { + var ID = $( this ).attr( 'id' ); + + if ( ID ) { + if ( 'checkbox' === $( this ).attr( 'type' ) && paymentDetails[ ID ] ) { + $( this ).prop( 'checked', true ); + } else { + $( this ).val( paymentDetails[ ID ] ); + } + } + }); + } + // Check for error if ( 'failure' === data.result ) { From 273952085c8546c7dac18e96837f799806d92c80 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Tue, 24 Jan 2017 20:35:06 -0600 Subject: [PATCH 2/4] Trigger change() when refilling payment details --- assets/js/frontend/checkout.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index d6500a53f9e..b4924aac00b 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -324,9 +324,9 @@ jQuery( function( $ ) { if ( ID ) { if ( 'checkbox' === $( this ).attr( 'type' ) && paymentDetails[ ID ] ) { - $( this ).prop( 'checked', true ); + $( this ).prop( 'checked', true ).change(); } else { - $( this ).val( paymentDetails[ ID ] ); + $( this ).val( paymentDetails[ ID ] ).change(); } } }); From ded7914dbadf127b01a8bbcc36eb37061bd23e89 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Tue, 24 Jan 2017 21:11:39 -0600 Subject: [PATCH 3/4] Add support for radio buttons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stripe’s saved card radio options for example. --- assets/js/frontend/checkout.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index b4924aac00b..6c9269f441b 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -296,7 +296,7 @@ jQuery( function( $ ) { var ID = $( this ).attr( 'id' ); if ( ID ) { - if ( 'checkbox' === $( this ).attr( 'type' ) ) { + if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) { paymentDetails[ ID ] = $( this ).prop( 'checked' ); } else { paymentDetails[ ID ] = $( this ).val(); @@ -323,8 +323,8 @@ jQuery( function( $ ) { var ID = $( this ).attr( 'id' ); if ( ID ) { - if ( 'checkbox' === $( this ).attr( 'type' ) && paymentDetails[ ID ] ) { - $( this ).prop( 'checked', true ).change(); + if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) { + $( this ).prop( 'checked', paymentDetails[ ID ] ).change(); } else { $( this ).val( paymentDetails[ ID ] ).change(); } From 4f9aebd69049f864e7e51a7acb95fe8d5d5e88a5 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Tue, 24 Jan 2017 21:19:10 -0600 Subject: [PATCH 4/4] Spacing New editor probs --- assets/js/frontend/checkout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index 6c9269f441b..cb3e4891d39 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -324,7 +324,7 @@ jQuery( function( $ ) { if ( ID ) { if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) { - $( this ).prop( 'checked', paymentDetails[ ID ] ).change(); + $( this ).prop( 'checked', paymentDetails[ ID ] ).change(); } else { $( this ).val( paymentDetails[ ID ] ).change(); }