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

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!

14 Answers

✔️Accepted Answer

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.

Related Issues:

3
webshim TypeError: a.swap is not a function in form-validation.js:1:5199 w/ jQuery 1.12.0
I ran across this issue after a Rails app was upgraded last week to address CVEs in a set of standar...