Skip to content

Commit

Permalink
Validate address form
Browse files Browse the repository at this point in the history
  • Loading branch information
vitkx committed Jan 7, 2025
1 parent f5ee386 commit d6ca1fc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/views/spree/checkout/payment/_paypal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

<script>
paypal.Buttons({
onClick: function(data, actions) {
const form = jQuery('form')[0];
if (
jQuery("input[name=order\\[bill_address_id\\]].other-address")[0] &&
jQuery("input[name=order\\[bill_address_id\\]].other-address")[0].checked
||
jQuery("input[name=order\\[bill_address_id\\]].other-address").length == 0
) {
if (form.checkValidity()) {
return actions.resolve();
} else {
form.classList.add('was-validated');
return actions.reject();
}
}
},
createOrder: async function(data, actions) {
try {
const response = await fetch('/paypal/create_order', {
Expand Down Expand Up @@ -38,6 +54,9 @@
onApprove: function(data, actions) {
const formData = new FormData(jQuery('form')[0]);
formData.delete('_method');
if (jQuery("input[name=order\\[bill_address_id\\]].other-address")[0] && !jQuery("input[name=order\\[bill_address_id\\]].other-address")[0].checked) {
formData.delete('order[bill_address_attributes][id]');
}
formData.append('payment_method_id', '<%= payment_method.id %>');
formData.append('orderID', data.orderID);
return fetch('/paypal/capture_order', {
Expand Down

0 comments on commit d6ca1fc

Please sign in to comment.