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

Prefix Formatting Bug when using default value #157

Closed
bennnjamin opened this issue Feb 14, 2017 · 2 comments · May be fixed by badsaarow/cleave.js#41
Closed

Prefix Formatting Bug when using default value #157

bennnjamin opened this issue Feb 14, 2017 · 2 comments · May be fixed by badsaarow/cleave.js#41

Comments

@bennnjamin
Copy link

I discovered this when I was trying to write a custom Phone Number formatter using (NPA) NXX-xxxx format. Using a prefix, in this case '(' and a default value on the input element causes a strange issue where it drops the second character.

jsFiddle: https://jsfiddle.net/1notekwr/

@nosir
Copy link
Owner

nosir commented Mar 25, 2017

Guess you can do like this:
https://jsfiddle.net/nosir/aoy6o9h9/
Just bear in mind that prefix is counted as part of raw value, so if you are setting the default value attr, you will need to include '(' as well.

Basically, your requirement is beyond the basic options cleave supports. But still, by doing so as in the fiddle, the formatter itself works fine. The only thing is when you call cleave.getRawValue(), you will need to strip the prefix '(' manually.

Will close this, let me know if you have any problem.

@nosir nosir closed this as completed Mar 25, 2017
@illycz
Copy link

illycz commented Jun 17, 2019

Prefix remove default value: https://jsfiddle.net/illycz/rfzy7o8m/ (second example).

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

Successfully merging a pull request may close this issue.

3 participants