Jul 29, 2015, 4:39 PM
TextField Selection window.getSelection() Is Blank or Undefined
I can not get the selected area from an EXT.NET textfield. No matter what variation i try to access, it will always be an empty string.
What am I doing wrong?
FYI: this solution no longer works. http://forums.ext.net/showthread.php...ll=1#post75467
What am I doing wrong?
FYI: this solution no longer works. http://forums.ext.net/showthread.php...ll=1#post75467
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
}
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<ext:XScript runat="server">
<script>
var KeyCheck = function (field, e) {
if (e.ctrlKey && e.getKey() === e.X) {
e.Handled = true;
var text = "";
if (window.getSelection
&& window.getSelection().toString()
&& $(window.getSelection()).attr('type') != "Caret") {
text = window.getSelection();
}
else if (document.getSelection
&& document.getSelection().toString()
&& $(document.getSelection()).attr('type') != "Caret") {
text = document.getSelection();
}
else {
var selection = document.selection && document.selection.createRange();
if (!(typeof selection === "undefined")
&& selection.text
&& selection.text.toString()) {
text = selection.text;
}
alert(text);
}
}
}
</script>
</ext:XScript>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<div>
<ext:Container runat="server" Layout="Fit">
<Items>
<ext:TextField ID="txtEntry" runat="server" Width="150" Text="Select a portion of this text and hit Ctrl + X" EnableKeyEvents="true">
<Listeners>
<KeyDown Fn="KeyCheck" />
</Listeners>
</ext:TextField>
</Items>
<Content>
</Content>
</ext:Container>
</div>
</form>
</body>
</html>
Last edited by pmaidlow; Jul 29, 2015 at 4:42 PM.
Reason: adding previous post non-working solution