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

JavaScript Issue...

Discussion in 'XenForo Development Discussions' started by Liam W, May 3, 2014.

  1. Liam W

    Liam W Well-Known Member

    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?
     
  2. Liam W

    Liam W Well-Known Member

    I'm starting to pull my hair out over this, it makes no sense...
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    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:

     
    Liam W likes this.
  4. Liam W

    Liam W Well-Known Member

    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.
     
  5. Liam W

    Liam W Well-Known Member

    Doh!

    I hadn't passed the function name as a string :/
     

Share This Page