Event when validation OK

How to trigger a custom PayPal button only after form validation in ChronoForms v6.

Overview

The custom PayPal button's JavaScript event listener was processing payments even when form data failed validation.
Wrap the button's click event handler in a conditional check using jQuery to verify the form's validation status before proceeding.

Answered
ChronoForms v6
dz dzseti 14 Apr, 2017
Have successfully set up a form with the new CFv6 module. It starts a GoCardless recurring payment process on submit (as CFv6 is intended to work) however it also has a PayPal button using the Braintree payment processor. This button and the processing behind it has been added as a custom js script. In the heart of the script is an event listener that triggers when the button is clicked:

paypalButton.addEventListener('click', function (event) {...})


Essentially it works fine during testing, but I would like this button only to start PayPal processing, if the form data has been validated and is OK to submit. The use-CFv6-as-intended GoCardless submit button only continues the payment process, if the form has been validated - just as it should - , but the PayPal button will start the PayPal payment process even if the form data is not validated.

What event listener should I use in the custom js script to trigger only if the form data has been validated?

This is private content

Max_admin Max_admin 15 Apr, 2017
Hi dzseti,

You may try this code, but I'm not sure if it will work:

if(jQuery(paypalButton).closest("form").form('is valid') == true){
//run some code here if the form is valid
}


so that code should be called when the button is clicked.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dz dzseti 15 Apr, 2017
Answer
This:
if (!jQuery('button#paypal-button').closest('form').form('is valid')) { // Not Valid
          return false;
        } else {
worked a treat. Many thanks🙂
This topic is locked and no more replies can be posted.