I have a simple payment form on my website with an option to pay with paypal express checkout. The rest of my form is validated with jquery validation.
How can I set it
the PayPal new API allows to validate a form that way There is no need to use the onInit func):
paypal
.Buttons({
// Run when the user click on the paypal button
onClick: function(data, actions) {
// My validation...
url = searchInput.value
// My validation Function...
const isURL = validURL(url)
if (isURL) {
// Remove Existing Error message
if (searchError.classList[2]) {
searchError.classList.remove('err-message--show')
}
// Enable The Paypal Button
return true
} else {
// Add Error messages
searchError.classList.add('err-message--show')
// The paypak wont continue to the paypal page...
return false
}
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [
{
amount: {
value: price,
currency_code: 'ILS'
}
}
]
})
}
.render('#paypal-button-container')
There also onApproval and onError functions... (handle the result of the PayPal process...)
Hope I helped, Naveh
There's a full example here:
https://developer.paypal.com/demo/checkout/#/pattern/validation
In the validate() function you need to listen for the form changing and enable/disable the button.