Cleave.js: Ability to get raw value by default

Created on 14 Apr 2017  Â·  5Comments  Â·  Source: nosir/cleave.js

Hi,
How can I get raw value with input.val() by default?
I'm trying to use Cleave with external credit card validator and when validator gets value of input using jQuery.val() it's failed on Cleave mask, because value is not looks like credit card number.

For example in Robin Herbots mask plugin — https://github.com/RobinHerbots/Inputmask — it can be achived using autoUnmask option.

Most helpful comment

Sorry, maybe I was not clear in my issue, but the problem with external validators depends on how validators gets data from input with Cleave.
In my situation, external validator request value of input after blur event and I can't add call for getRawValue directly, in this case option like autoUnmask will be good, but not necessary.
Btw, I achieved my task with jQuery valHooks:

        var cleave = new Cleave('#iPAN', {
            creditCard: true
        });
        $.valHooks['input'] = {
            get : function(el) {
              if (el.id === 'iPAN') {
                return cleave.getRawValue();
              }
              return el.value;
            },
            set : function(el, val) {
              $(el).html(val);
            }
        };

All 5 comments

input.val() is a jquery method, it returns the actual value you are seeing, which would be: 5163 0000 1234 5678 with spaces in it.

If you are looking to get raw value without spaces, please check this: https://github.com/nosir/cleave.js/blob/master/doc/public-methods.md#getrawvalue

And then you can pass the raw value to your external credit card validator.

Sorry, maybe I was not clear in my issue, but the problem with external validators depends on how validators gets data from input with Cleave.
In my situation, external validator request value of input after blur event and I can't add call for getRawValue directly, in this case option like autoUnmask will be good, but not necessary.
Btw, I achieved my task with jQuery valHooks:

        var cleave = new Cleave('#iPAN', {
            creditCard: true
        });
        $.valHooks['input'] = {
            get : function(el) {
              if (el.id === 'iPAN') {
                return cleave.getRawValue();
              }
              return el.value;
            },
            set : function(el, val) {
              $(el).html(val);
            }
        };

I have a similar issue. Looks like there is no option to set it yet.

I want to post currencies as their raw values. Application have an i18n layer and users format number in varying ways. Standardizing them on the back end is not a good practice.

I agree with @zortext here, experiencing the exact same issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

periabyte picture periabyte  Â·  7Comments

ArtyomBist picture ArtyomBist  Â·  6Comments

Jahleel17 picture Jahleel17  Â·  3Comments

melbon picture melbon  Â·  3Comments

YanikCeulemans picture YanikCeulemans  Â·  3Comments