开发者

using jquery masked input for updating values

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 开发者_StackOverflowis 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?


Try to fire 'click' event programmatically:

$(document).ready(function() {
   $("#isNo").mask("(999) 999-9999").click();
});


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜