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

JavaScript Issue...

Liam W

Well-known member
#1
I'm stumped on this, can someone here help me out?

I've created a javascript file and have registered something, as per the file below...

Code:
/**
* @param {jQuery} $
*            jQuery Object
*/
!function($, window, document, _undefined) {

    XenForo.VPPCodes = {
        ShowCode : function($form) {
            console.log($form);

            $form.bind('AutoValidationComplete', function(e) {

            });
        }
    };

    XenForo.register('form.VPPForm', XenForo.VPPCodes.ShowCode);

}(jQuery, this, document);
However, the $form variable just contains 0 and as such an error is thrown when I try to bind an event handler to it (or whatever it's called).

Any ideas?
 

Chris D

XenForo developer
Staff member
#3
Most XenForo JS takes this format:

Code:
/** @param {jQuery} $ jQuery Object */
!function($, window, document, _undefined)
{
    XenForo.VPPCodesShowCode = function($form)
    {
        console.log($form);
    };

    XenForo.register('form.VPPForm', 'XenForo.VPPCodesShowCode');
}
(jQuery, this, document);
For me, it works fine:

[form.VPPForm, context: form.VPPForm, jquery: "1.11.0", constructor: function, selector: "", toArray:function…]
 

Liam W

Well-known member
#4
Most XenForo JS takes this format:

Code:
/** @param {jQuery} $ jQuery Object */
!function($, window, document, _undefined)
{
    XenForo.VPPCodesShowCode = function($form)
    {
        console.log($form);
    };

    XenForo.register('form.VPPForm', 'XenForo.VPPCodesShowCode');
}
(jQuery, this, document);
For me, it works fine:
I changed it to that after making this post and it had the same issue.

I'll try again after I've had some lunch... And a drink.