I'm currently upgrading our Braintree SDK which uses JavaScript to hijack the Rails form 'submit' button, makes a call to Braintree.js, and on success, allows us to Post our data as normal.
The issue is that we are already piggybacking on the submit button, checking form data with a few JavaScript methods, then calling $form.submit()
to continue Posting the data. The two are conflicting.
My solution is to create a fake "submit" button and on click, have it run the methods to verify data, THEN have it call $form.submit()
, allowing Braintree.js to hijack the real submit button. Am I not correctly invoking the submit call on the form?
My fake submit button followed by the actual submit button (with id: place_order_submit)...
%p.advance-container.clearfix
%input#check-order.btn.btn-xlarge.btn-primary.action-check-order{type: 'button', value: 'Check Order'}
%input#place_order.btn.btn-xlarge.btn-primary.action-submit{type: 'submit', id: 'submit', value: 'Place Order'}
This is the Coffeescript that should do its thing (i.e. double check the order) then "click" the submit form button to have it process/post as normal (allowing it to be hijacked by Braintree).
$form: $('form')
$formGroups: $(".form-group")
formGroupIds: $('.form-group').map -> $(this).attr('id')
lastFormGroupId: $(".form-group").last().attr('id')
$checkOrderButton: $('#check-order')
@$checkOrderButton.on 'click', (event)=>
event.preventDefault()
try
q.Orders.items.isAssertAllAvailablePollEnabled = false
@$pageCover.show()
$.when(@items.ensureAllAvailable(), @shippingAddr.save(), @billingAddr.save())
.done =>
q.Logger.debug 'pre-Braintree requests done, go!'
q.Util.resetSubmissionState 'form'
@$checkOrderButton.off('click')
$('#place_order_submit').submit() # <-- THIS ISN'T WORKING
.fail ->
q.Orders.items.isAssertAllAvailablePollEnabled = true
q.Logger.warn "At least one pre-Braintree request failed, submit halted. Details: #{JSON.stringify(this, null, 4)}"
q.Util.resetSubmissionState 'form'
@$pageCover.hide()
catch ex
q.Logger.warn "pre-Braintree request failed with exception: #{ex}"
q.Util.resetSubmissionState 'form'
@$pageCover.hide()
Aucun commentaire:
Enregistrer un commentaire