Backspace

  1. #1

    Backspace

    We have some threads related to backspace, such:


    Daniil provided a solution on: http://forums.ext.net/showthread.php...l=1#post117215
    <ext:KeyMap runat="server" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}">
        <Binding>
            <ext:KeyBinding Handler="console.log('just some handler');" DefaultEventAction="StopEvent">
                <Keys>
                    <ext:Key Code="BACKSPACE" />
                </Keys>
            </ext:KeyBinding>
        </Binding>
    </ext:KeyMap>
    Geoffrey wrote on http://forums.ext.net/showthread.php...l=1#post124162
    Maybe we can build a property into Ext.NET to avoid this backspace issue. I too agree that it can be very annoying.
    So, it would be nice to have this implemented on version 4.x.

    Thanks in adavance.
    Last edited by RaphaelSaldanha; Apr 18, 2016 at 4:47 PM.
  2. #2
    Daniil provided a solution on: http://forums.ext.net/showthread.php...l=1#post117215
    <ext:KeyMap runat="server" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}">
        <Binding>
            <ext:KeyBinding Handler="console.log('just some handler');" DefaultEventAction="StopEvent">
                <Keys>
                    <ext:Key Code="BACKSPACE" />
                </Keys>
            </ext:KeyBinding>
        </Binding>
    </ext:KeyMap>
    Unfortunately that solution prevents backspace on TextField and on TextArea, as shown below
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" runat="server" />
        <ext:KeyMap Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}" runat="server">
            <Binding>
                <ext:KeyBinding Handler="console.log('just some handler');" DefaultEventAction="StopEvent">
                    <Keys>
                        <ext:Key Code="BACKSPACE" />
                    </Keys>
                </ext:KeyBinding>
            </Binding>
        </ext:KeyMap>
        <ext:TextField Text="Text" runat="server" />
        <ext:TextArea Text="Text" runat="server" />
    </body>
    </html>
  3. #3
    The solution provided on http://stackoverflow.com/a/24633960, suggested by Geoffrey as a good thread, http://forums.ext.net/showthread.php...l=1#post124163, seems to be a good approach.

    But since Ext.EventManager is deprecated, it's necessary to replace it by Ext.dom.Element#addListener, as stated on http://docs.sencha.com/extjs/6.0/6.0...t-EventManager.

    So, we have the following:
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            Ext.getWin().on('keydown', function (e, t) {
                var nodeName = e.target.nodeName.toLowerCase();
                if (e.getKey() == e.BACKSPACE) {
                    if (nodeName !== 'input' && nodeName !== 'textarea' || e.target.type === 'button') {
                        console.log('Preventing - ' + new Date());
                        e.preventDefault();
                    }
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" runat="server" />
        <ext:TextField Text="Text" runat="server" />
        <ext:TextArea Text="Text" runat="server" />
    </body>
    </html>
    Last edited by RaphaelSaldanha; Apr 18, 2016 at 6:14 PM.

Similar Threads

  1. Replies: 1
    Last Post: Aug 20, 2015, 3:33 PM
  2. [CLOSED] Disable backspace (but only when not in textfield/textarea)
    By CarWise in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 11, 2013, 1:27 PM
  3. [CLOSED] Backspace and KeyPress
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 21, 2012, 2:35 PM
  4. [CLOSED] Problem with backspace key
    By skisly in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 21, 2011, 12:26 PM
  5. [CLOSED] Backspace
    By jeybonnet in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 25, 2011, 2:41 PM

Posting Permissions