question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why there is no jquery version?

See original GitHub issue

kind of (+autoUnmask option for numeric):

$('#price,#sum').cleave({ numeral: true, numeralThousandsGroupStyle: 'thousand', autoUnmask: true});
(function($, window, undefined){ 'use strict'

  $.fn.cleave = function(opts) {

    var defaults = {autoUnmask: false},
        options = $.extend(defaults, opts || {});

    return this.each(function(){

      var cleave = new Cleave('#'+this.id, options), $this = $(this);

      $this.data('cleave-auto-unmask', options['autoUnmask']);;
      $this.data('cleave',cleave)
    });
  }

  var origGetHook, origSetHook;

  if ($.valHooks.input) {

    origGetHook = $.valHooks.input.get;
    origSetHook = $.valHooks.input.set;

  } else {

    $.valHooks.input = {};
  }

  $.valHooks.input.get = function (el) {

    var $el = $(el), cleave = $el.data('cleave');

    if( cleave ) {

      return $el.data('cleave-auto-unmask') ? cleave.getRawValue() : el.value;

    } else if( origGetHook ) {

      return origGetHook(el);

    } else {

      return undefined;
    }
  }

  $.valHooks.input.set = function (el,val) {

    var $el = $(el), cleave = $el.data('cleave');

    if( cleave ) {

      cleave.setRawValue(val);
      return $el;

    } else if( origSetHook ) {

      return origSetHook(el);

    } else {
      return undefined;
    }
  }
})(jQuery, window);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Swizzycommented, Apr 4, 2019

The line “var cleave = new Cleave(‘#’+this.id, options), $this = $(this);” should be “var cleave = new Cleave(this, options), $this = $(this);” to be fully compatible, you are otherwise assuming that whatever was passed to the JQuery function has an ID which may or may not be true

1reaction
kevyworkscommented, Mar 20, 2021

Just a minor change for others.

var cleave = new Cleave('#'+this.id, options), $this = $(this);
// should be
var $this = $(this), cleave = new Cleave($this.first(), options);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why jQuery is Obsolete and Time to Stop Using It - Love2Dev
What Causes jQuery Version Fragmentation? There is no one single answer to this question as most sites will have more than one reason....
Read more >
5 Easy Ways to Fix the "jQuery is Not Defined" Error - Kinsta
The "jQuery is not defined" error means a call for a specific jQuery that wasn't available when the website loaded. Here's how to...
Read more >
How to upgrade to the latest version of jQuery
Upgrading to the latest version of jQuery makes your website more secure, and potentially a little faster in terms of script execution time...
Read more >
Should You Be Using JQuery 3.4? - Webdesigner Depot
jQuery 3.4 is now publicly available. With a raft of options for JavaScript developers, we ask if there's still room for the original ......
Read more >
jQuery version incorrect - UberMenu Troubleshooter Diagnosis
Newer versions of jQuery include functions not available in older versions. If your theme or another plugin loads an older version of jQuery,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found