1

i have a problem with masked input plugin. in my header i have

$("#isNo").mask("(999) 999-9999");

and my input field is;

<h:inputText value="#{bBean.PhoneNr}" id="isNo" />

so, when bBean.PhoneNr is empty, there is no problem, because textbox is rendered with null value in it. mask is successful. But when bBean.PhoneNr is something like 5123123123, if i dont click that text field, value remains same = 5123123123. if i click that text field it becomes (512) 312-3123. do you have an idea to correct that value to be masked before textbox clicking?

2 Answers 2

1

Try to fire 'click' event programmatically:

$(document).ready(function() {
   $("#isNo").mask("(999) 999-9999").click();
});
Sign up to request clarification or add additional context in comments.

3 Comments

hi, thank you for your response, i tried but it didn't work. i think click() evet occurs before setting the value of textfield, so i didn't get it worked. am i wrong?
I've specially tested - it works! jsfiddle.net/8QPhw - please see it. And it's working even without my "improvements" :) jsfiddle.net/8QPhw/1
thank you, its completely my fault.. I was using maskedinput v1.0.. Changed to 1.3 solved it. both with click() and without click() works also..
1

You can remove the mask and reset it...

$("#isNo").val("NewPhoneNumber").unmask().mask("(999) 999-9999", {clearIfNotMatch: true});

This worked for me and should solve your problem!

TLDR: .unmask() before .mask()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.