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.
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
This might help: https://github.com/nosir/cleave.js/issues/397#issuecomment-607165379
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
getRawValuedirectly, in this case option like autoUnmask will be good, but not necessary.Btw, I achieved my task with jQuery valHooks: