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

Get the value from the last character to left. #13

Open
mauriciosoares opened this issue Feb 17, 2016 · 3 comments
Open

Get the value from the last character to left. #13

mauriciosoares opened this issue Feb 17, 2016 · 3 comments

Comments

@mauriciosoares
Copy link

Hey, the title might seem a little confusing, but an example can make it very clear. Let's say I have the following pattern:

  var mask = new InputMask({pattern: '11/11/1111'});

  mask.paste('111');

If I use the getValue method, I get the string '11/1_/____'.

Is there a way to get only the characters from the last 1 to the left? it would return something like this: 11/1

thanks.

@iamdustan
Copy link
Collaborator

I believe there is a getRawValue() that will get you something close to that.

@mauriciosoares
Copy link
Author

thanks @iamdustan

yes, getRawValue would return in the previous example 111.

But I do need the mask, but I need only the ones that are to the left of my last character, that's why in my example I get only one /. The number of characters retrieved does matter for my case...

the getValue would return a string with a length of 10. (even if I paste only a 111)
the getRawValue would return a string with a length of 3.
My example returns a string with a length of 4.

@mauriciosoares
Copy link
Author

Just to let you know, I achieved this by doing some crazy hack, here's the snippet:

var instance = new InputMask({pattern: mask, value});
value.split('').forEach(s => instance.input(s));
const {end} = instance.selection;
return instance.getValue().slice(0, end);

Basically, I manually input each of the characters in the instance (had to use input instead of paste, if 1 single character is wrong in the paste method, it just dont paste anything);

After that I get the end property from the selection object, and slice the getValue value from 0 to the end number.

Still I'd like to know if there's a better approach :)

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

2 participants