Skip to content
This repository was archived by the owner on Dec 11, 2017. It is now read-only.

Apply/Remove the mask when re-masking a field#44

Closed
galaban wants to merge 1 commit intodigitalBush:masterfrom
galaban:master
Closed

Apply/Remove the mask when re-masking a field#44
galaban wants to merge 1 commit intodigitalBush:masterfrom
galaban:master

Conversation

@galaban
Copy link

@galaban galaban commented Jul 14, 2011

There are two problems that I solved with this fix.

  1. By initializing the buffer[] to the focus text, I was able to send data to the control and have it be correctly populated. So, if I clicked on the textbox and immediately hit Escape, the data would stay there.

  2. When attempting to re-mask the field, I got some wild results. Going from a mask of "999-99-99" to "9999999" caused the mask to be nine characters long, adding the placeholder where the original dashes were and causing the input to go into the places where the original mask specified. (Ugh. Just not good.)

To recreate:
Begin with a mask:
input.mask('999-99-99', {placeholder:'0'});
Then change the mask dynamically:
input.mask('9999999', {placeholder:'0'});

The fix was to remove the mask when we did the UnMask, storing the original data (NOT the masked data but the actual values entered) into the original text box.

I have only tested this on IE8, so you should probably double check it.

@digitalBush
Copy link
Owner

I'm not sure what is wrong with the behavior as it is. http://jsfiddle.net/GMvHg/

It seems to work as you describe it should.

@galaban
Copy link
Author

galaban commented Sep 7, 2011

That's odd! It seems to work well on jsfiddle, but not on my box. (Yeah, I know that doesn't help much, does it?)

In fact, it's not behaving at all like what I'm seeing. I'm not sure if this is due to other code we have in place, other code jsfiddle has in place, or possibly differences in framework. But I know that this change fixed the problem we were having and it seems to work nicely with the code.

I thought I'd just share this with you in case you wanted to add it. I noticed someone else had a similar problem with initializing the buffer[]. (Issue #35, #35)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants