Skip Navigation

[Résolu] How to trigger JQuery on form submission error

This support ticket is created Il y a 3 années et 11 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 2 réponses, has 2 voix.

Last updated by davidS-53 Il y a 3 années et 11 mois.

Assisted by: Jamal.

Auteur
Publications
#1590609

This seems like a fairly simple request, but I haven't been able to find an answer in the forums.

I have a loading spinner on my site, but I need to hide it if someone submits a form and there's a validation error- for example, they haven't filled out a required field. So all I want to do is to run this bit of JQuery:

$('.loading-spinner').fadeOut();

If a form triggers an error on submit. What's the best way to achieve that? Thanks in advance!

#1590843

Jamal
Supporter

Languages: Anglais (English ) Français (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

Currently, there is no Javascript API for Toolset Forms. If you need an API, please suggest it on this page https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Without proper API from Toolset Forms, you will need to come up with a hacky solution, which will depend on your use case(theme, HTML markup, etc.) Check this article about intercepting AJAX requests: hidden link

You can create your custom ajaxSetup and hide the spinner whenever an AJAX call is ended. You may need to do some checks and hide the spinner only for the form AJAX call. (Prefer jQuery over $, $ won't work on WP environement)

jQuery(function($){
    $.ajaxSetup({
        complete: function (xhr,status) {
            // check if we need to hide the spinner and hide it.
        },
        error: function (xhr,status,error) {
            // check if we need to hide the spinner and hide it.
        }
    })
})

Please note, that custom code is beyond the scope of the support forum, If you are not comfortable with programming, consider hiring a developer or one of our partners https://toolset.com/contractors/

#1591149

Thanks, I'll be able to sort from here.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.