0

Stripe checkout is not validating required input fields.

required field:

<input type="tel" name="appointment[patient_phone]" id="appointment_patient_phone" required="required" placeholder="Phone Number">

When I click on the stripe button, the stripe checkout popup appears and form is not validated.

So I tried and add a custom validator but stopPropagation is not working as the stripe checkout popup still pops up after alert and stopPropagation is called

function validateAppointmentForm() {

  var validateForm = function(event) {
    debugger;
    var phone = $('#appointment_patient_phone').val();
    if (!phone) {
      alert("Phone number is required.");
      event.preventDefault();
      event.stopPropagation();
    }
  }

  var watchStripeButton = function() {
    debugger;
    $("#new-appt-stripe-button").on("click", validateForm);
  }

  debugger;
  watchStripeButton();

}
;

1 Answer 1

1

You should use Custom Checkout here instead. This allows you to have your own button and add validation to your form before opening Checkout.

When the customer clicks on your button to pay and enter his card details, you'll detect some fields are not filled properly or have an invalid value and display an error. If the form validates you can then call handler.open() in the click handler.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.