[CLOSED] [1.1] Prevent backspace on readonly field on ie

  1. #1

    [CLOSED] [1.1] Prevent backspace on readonly field on ie

    Hi, I write the follow code:

    <%@ Page Language="C#" AutoEventWireup="True" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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 id="Head1" runat="server">
        <title></title>
    </head>
    
    
    <body>
    
    
    <script>
        var _common_preventBackspace_2 = function (field, e) {
            alert('..');
            if (e.getKey() == e.BACKSPACE) {
                alert('');
                e.preventDefault();
                return false;
            }
        }
    </script>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Gray" CleanResourceUrl="false" />
        
       <ext:TextField runat="server" ID="tb" EnableKeyEvents="true" ReadOnly="true" Text="ddd">
       <Listeners >
       <KeyPress  Fn="_common_preventBackspace_2" /> 
       </Listeners>
       </ext:TextField>
        
        </form>
    </body>
    </html>
    This work on mozilla and chrome, but in Ie 8/9 che event is not fired and the browser go to previous page.

    What I wrong?

    Thanks
    Last edited by Daniil; Sep 20, 2011 at 10:37 AM. Reason: [CLOSED]
  2. #2
  3. #3
    Thanks Daniil,
    there is a way to filter to prevent a backspace? because in my items collection I have more textfield control, and more than one are not readonly.

    If I used keymap I prevent all backspace key and I not able to delete a char.

    Thanks
  4. #4
    I can suggest the solution below.

    Example

    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:KeyMap runat="server" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}">
                <ext:KeyBinding>
                    <Keys>
                        <ext:Key Code="BACKSPACE" />
                    </Keys>
                    <Listeners>
                        <Event Handler="var id = Ext.fly(e.getTarget()).getAttribute('id'),
                                            t = Ext.getCmp(id),
                                            v;
                                        if (t instanceof Ext.form.TextField) {
                                            e.preventDefault();
                                            if (!t.readOnly) {
                                                v = t.getValue();
                                                if (v) {
                                                    t.setValue(v.substring(0, v.length - 1));
                                                }    
                                            }
                                        };" />
                    </Listeners>
                </ext:KeyBinding>
            </ext:KeyMap>
            <ext:TextField 
                runat="server" 
                ReadOnly="true" 
                Text="Text" 
                FieldLabel="ReadOnly" />
            <ext:TextField 
                runat="server" 
                ReadOnly="false" 
                Text="Text" 
                FieldLabel="Not ReadOnly" />
            <ext:TextField 
                runat="server" 
                ReadOnly="true" 
                Text="Text" 
                FieldLabel="ReadOnly" />
        </form>
    </body>
    </html>
  5. #5
    Thanks Daniil, its works.

Similar Threads

  1. [CLOSED] Field ReadOnly Javascript
    By Aurelio in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Mar 22, 2012, 10:48 AM
  2. [CLOSED] TextField KeyPress handler for the Backspace key
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Mar 15, 2012, 1:01 PM
  3. [CLOSED] Problem with backspace key
    By skisly in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 21, 2011, 12:26 PM
  4. [CLOSED] Backspace
    By jeybonnet in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 25, 2011, 2:41 PM
  5. [CLOSED] How to prevent users from entering characters in Trigger Field
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 16, 2010, 5:44 PM

Tags for this Thread

Posting Permissions