• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Extend AutoValidator/Ignore errors

rugk

Active member
#1
I want to automatically trigger a button/submit a form, which is using the XenForo AutoValidator.
However, I want to "catch" the error, so it does not show the error overlay it usually does if an error happens.

The aim is to hide the button, so that the "form confirmation" happens automatically and users do not need to click any button.

XenForo's obfuscated/minified JavaScript code makes it hard to find out what needs to be done to achieve this.
For the curious: The form I am handling is the Tfa/2FA form with the submit button.

So how can I do this?
 
Last edited:

Mike

XenForo developer
Staff member
#2
Your download includes the unminified JS files if that's helpful.

You can listen to the AutoValidationError event on the form and prevent default within that to stop the error overlay. To automatically trigger the form, you should just be able to call submit on it via JS.
 

rugk

Active member
#3
Nice, this works!
Also thanks for the hint to the unmodified JS files. They are in the directory /full.
Just how do I now hide the AJAX loading indicator (#AjaxProgress) persistently? As it is automatically shown when an AJAX call is created, I cannot just use some CSS to do so.
 

rugk

Active member
#4
Okay, so what I basically did is wrapping #AjaxProgress into a new div, which I then hide if necessary. As #AjaxProgress is only created when an AJAX request actually starts you need to listen for the event ajaxStart and c an then do the things you need to do.

However, if there are any better ideas, please fell free to share them.
 
Last edited:

Mike

XenForo developer
Staff member
#5
Just so you know, you can prevent the global action indicator but only if you control the ajax call params. It's the "global" option. Here's an example from the autocomplete code:
Code:
this.acXhr = XenForo.ajax(
   this.url,
   { q: this.lastAcLookup },
   $.context(this, 'showAutoCompleteResults'),
   { global: false, error: false }
);