Skip to content

Commit

Permalink
Prevent multiple modal submits. Propagate show/if logic by firing a c…
Browse files Browse the repository at this point in the history
…hange event on the shown/hidden input.
  • Loading branch information
dennisnissle committed Jul 18, 2024
1 parent 7e77573 commit d5354cf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion assets/js/static/admin-shipment-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ window.germanized.admin = window.germanized.admin || {};
}
}

// Make sure to propagate show/if logic by firing a change event on the shown/hidden input.
$wrapper.find( ':input[data-show-if-' + fieldId + ']' ).trigger( 'change' );

/**
* Hide the show more trigger in case no visible field is found within the wrapper.
* Explicitly check for the display style as the wrapper may be in collapsed state.
Expand Down Expand Up @@ -266,7 +269,9 @@ window.germanized.admin = window.germanized.admin || {};
});
}

self.$modal.find( '#btn-ok' ).prop( 'disabled', false );
self.$modal.find( '.wc-backbone-modal-content' ).unblock();

cSuccess.apply( self, [ data, self ] );

/**
Expand All @@ -286,7 +291,9 @@ window.germanized.admin = window.germanized.admin || {};
self.afterRefresh();
}
} else {
self.$modal.find( '#btn-ok' ).prop( 'disabled', false );
self.$modal.find( '.wc-backbone-modal-content' ).unblock();

cError.apply( self, [ data, self ] );

self.printNotices( $content, data );
Expand Down Expand Up @@ -454,7 +461,12 @@ window.germanized.admin = window.germanized.admin || {};
var self = event.data.adminShipmentModal,
$content = self.getModalMainContent(),
$form = $content.find( 'form' ),
params = self.getFormData( $form );
params = self.getFormData( $form ),
$submit = self.$modal.find( '#btn-ok' );

if ( $submit.length > 0 ) {
$submit.prop( 'disabled', true );
}

params['security'] = self.getNonce( 'submit' );
params['reference_id'] = self.referenceId;
Expand Down

0 comments on commit d5354cf

Please sign in to comment.