Skip to content

Disabling submit with hosted fields #155

@rickhall

Description

@rickhall

I had contacted support with this question, but I'll re-enter it here to capture it.

I am using custom integration with hosted fields and I would like to disable the submit button while waiting to get the payment nonce. My current approach is to:

  1. Add a submit listener on the form which always disables the submit UI button upon seeing a submit event.
  2. In braintree onError callback, I re-enable submit button in case of any validation errors.
  3. In onPaymentMethodReceived callback, I then send the payment nonce to my server.

This basically works ok and prevents duplicate submits if and only if the user clicks on the “submit” button.

Unfortunately, if the user uses the "return" key to submit the form, then the native submit event isn’t fired. This makes it so I cannot give my user any visual feedback that something is going on, increasing the likelihood that they may try to resubmit if it takes a long time.

Perhaps I’m missing something, but I’ve searched the web a bit and it seems that a lot of people want to do this flow, but it is more difficult than it seems it should be. It seems like adding some sort of “beforeSubmit” callback after everything is validated, but just before submitting to braintree server would make this flow a lot more intuitive.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions