Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: a.swap is not a function in form-validation.js:1:5199 w/ jQuery 1.12.0 #560

Closed
AMA3 opened this issue Jan 11, 2016 · 13 comments
Closed

Comments

@AMA3
Copy link
Contributor

AMA3 commented Jan 11, 2016

Hi Alex,

When using the latest Webshim w/ the latest released jQuery 1.12.0, I get:

TypeError: a.swap is not a function

in form-validation.js line 1 char 5199.

This happens when I click on a field with type="month" or type="date" in Firefox 43.0.4 after initializing Webshim with:

        webshim.setOptions('extendNative',true);
        webshim.polyfill('forms forms-ext');

The problem does not occur if I revert to jQuery 1.11.3.

I believe the issue is caused by this "fix" in jQuery 1.12:

jquery/jquery@0019a46

Thank you!

@luishdz1010
Copy link

+1, I can reproduce this with the same configuration in Chrome 47

@wwuck
Copy link
Contributor

wwuck commented Jan 29, 2016

Looks like webshim is using an undocumented internal API function. Webshim needs to be updated to only call the public jQuery API functions.

jquery/jquery#2058
jquery/jquery@02a9d9f
jquery/jquery#2182

apohllo added a commit to apohllo/rocznik that referenced this issue Feb 3, 2016
More info about the problem at
aFarkas/webshim#560
@marvinrabe
Copy link

Error is also occuring with the current jQuery2 version (2.2). Its working fine with jQuery 2.1

@philayres
Copy link

I ran across this issue after a Rails app was upgraded last week to address CVEs in a set of standard Gems. The packaged JQuery must have been bumped, which led to this function being hidden from the published API.

For anybody needing a short term fix, I was able to regain the functionality by extracting the original JQuery code for .swap:

 jQuery.swap = function( elem, options, callback, args ) {
    var ret, name, old = {};
    // Remember the old values, and insert the new ones
    for ( name in options ) {
            old[ name ] = elem.style[ name ];
            elem.style[ name ] = options[ name ];
    }

    ret = callback.apply( elem, args || [] );

    // Revert the old values
    for ( name in options ) {
            elem.style[ name ] = old[ name ];
    }
    return ret;
};

Not a long term fix, but maybe useful for others who suddenly have broken Rails apps.

@brucek2
Copy link

brucek2 commented Mar 5, 2016

+1

@kattunga
Copy link

Hi philayres, can you explain me where to declare swap function?
I try to define in a js file that I included before polyfiller.js but it does'work.

@brucek2
Copy link

brucek2 commented Mar 10, 2016

I did exactly that and it worked -- make sure you are doing it after
loading jQuery though.

On Thu, Mar 10, 2016 at 10:24 AM, Christian Pradelli <
notifications@github.com> wrote:

Hi philayres, can you explain me where to declare swap function?
I try to define in a js file that I included before polyfiller.js but it
does'work.


Reply to this email directly or view it on GitHub
#560 (comment).

@kattunga
Copy link

Thank you bruce, now it works, I made I typo when I copy the code.

@PRISMAY
Copy link

PRISMAY commented Mar 11, 2016

Same problem in IE11. Project using jQuery 2.2.1 and webshims 1.15.10.

@jvanalst
Copy link

+1. Switching to jQuery 1.11.3 fixed the error.

@davidlbudiman
Copy link

Hi, this is my first post in GitHub.

I've encountered this issue using jQuery 3.x and I've found that webshims still only works with jQuery 1.8, after I've added jQuery-migrate the problem is fixed.

@HenriPodolski
Copy link

HenriPodolski commented Oct 17, 2016

Like mentioned above, you can just add the swap method: http://james.padolsey.com/jquery/#v=1.11.2&fn=jQuery.swap to your code to make this work. It has no other dependencies.

$.swap = function (elem, options, callback, args) {
    var ret, name, old = {};

    // Remember the old values, and insert the new ones
    for (name in options) {
        old[name] = elem.style[name];
        elem.style[name] = options[name];
    }

    ret = callback.apply(elem, args || []);

    // Revert the old values
    for (name in options) {
        elem.style[name] = old[name];
    }

    return ret;
}

@jab
Copy link
Contributor

jab commented Nov 27, 2016

After upgrading to 1.16.0 I was still able to reproduce this sometimes in Safari. Since this is the only thing I was using webshims for, I decided to ditch webshims in favor of a few lines of js based on http://codepen.io/ngault/pen/PqmyQE, and that's working better for me. (Now I'm free to upgrade to jQuery 3 too.) In case this helps anyone else here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests