Clarence Klopfstein
Top achievements
Rank 1
Clarence Klopfstein
asked on 24 Sep 2009, 03:15 PM
I have a masked text box for a phone number (###) ###-####.
But when the user clicks on the box it select whereever they clicked. Is there a way to make it act like a text box and go ot the far left place?
But when the user clicks on the box it select whereever they clicked. Is there a way to make it act like a text box and go ot the far left place?
3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 25 Sep 2009, 05:41 AM
Hi Clerence,
Try setting the property SelectionOnFocus="CaretToBeginning" and see whether it works as expected.
aspx:
-Shinu.
Try setting the property SelectionOnFocus="CaretToBeginning" and see whether it works as expected.
aspx:
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" DisplayMask="(###) ###-####" |
Mask="(###) ###-####" SelectionOnFocus="CaretToBeginning"> |
</telerik:RadMaskedTextBox> |
-Shinu.
0
Clarence Klopfstein
Top achievements
Rank 1
answered on 25 Sep 2009, 01:49 PM
This helped a little. If I go to the box via tab, it goes to the far left spot. However if I click on the box it goes to the end, or to the point I click. Would love if it auto determined where to go... like if I had (51_) ___-____ it would go to that third spot when I clicked on the box.
0
Hello Clarence,
I am afraid that such an auto-detecting behavior for the caret position is currently not supported. We may consider implementing it in the future. Sorry if this causes you inconvenience.
You can try using something like the following. MyFocus2 works better, but uses hardcoded numbers, which depend on the mask.
All the best,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I am afraid that such an auto-detecting behavior for the caret position is currently not supported. We may consider implementing it in the future. Sorry if this causes you inconvenience.
You can try using something like the following. MyFocus2 works better, but uses hardcoded numbers, which depend on the mask.
<%@ Page Language="C#" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml" > |
<head runat="server"> |
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> |
<title>RadControls for ASP.NET AJAX</title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<asp:ScriptManager ID="ScriptManager1" runat="server" /> |
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" Mask="(###)-##-######" Text="51" SelectionOnFocus="CaretToBeginning"> |
<ClientEvents OnFocus="MyFocus2" /> |
</telerik:RadMaskedTextBox> |
<script type="text/javascript"> |
function MyFocus1(sender, args) |
{ |
if (sender.get_value() != "") |
{ |
if (sender.get_valueWithLiterals().indexOf("--") != -1) |
{ |
sender.set_caretPosition(sender.get_value().length + 1); |
} |
else if (sender.get_valueWithLiterals().indexOf("-") != -1) |
{ |
sender.set_caretPosition(sender.get_valueWithLiterals().length); |
} |
else |
{ |
sender.set_caretPosition(sender.get_value().length + 1); |
} |
} |
} |
// or |
function MyFocus2(sender, args) |
{ |
var v = sender.get_value(); |
document.title = v.length + " " + v; |
if (v != "") |
{ |
if (v.length < 3) |
{ |
sender.set_caretPosition(v.length + 1); |
} |
else if (v.length < 5) |
{ |
sender.set_caretPosition(v.length + 3); |
} |
else |
{ |
sender.set_caretPosition(v.length + 4); |
} |
} |
} |
</script> |
</form> |
</body> |
</html> |
All the best,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.