[CLOSED] How to prevent clear textfield after keyboard ENTER was down

  1. #1

    [CLOSED] How to prevent clear textfield after keyboard ENTER was down

    Hi,
    Like in Title. Here is my code:
    <ext:Container ID="containerLogin" runat="server" Layout="Fit" Width="450" Height="180" StyleSpec="margin:140px auto;" HideBorders="True">
        <Items>
            
            <ext:FormPanel 
                ID="Window1" 
                runat="server"
                Resizable="false"
                MinHeight="150"
                MaxHeight="200"
                Icon="Lock" 
                Title="Log"
                Width="450"
                Cls="login-form"
                Padding="5" >
                <Items>
                    <ext:TextField 
                        ID="txtUsername" 
                        runat="server" 
                        FieldLabel="Login <span class='red'>*</span>"
                        AllowBlank="false"
                        BlankText="Login is required."
                        />
                    <ext:TextField 
                        ID="txtPassword" 
                        runat="server" 
                        InputType="Password" 
                        FieldLabel="Password <span class='red'>*</span>" 
                        AllowBlank="false" 
                        BlankText="Password is required."
                        EnableKeyEvents="True"
                        >
                        <Listeners>
                            <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.stopEvent();#{LoginButton}.fireEvent('click');}" />
                        </Listeners>
                    </ext:TextField>
                     <ext:Checkbox 
                        runat="server" 
                        ID="chRemember" 
                        Checked="False" 
                        FieldLabel="Remember login and password"
                        ></ext:Checkbox>
                </Items>
                <Buttons>
                    <ext:Button ID="LoginButton" runat="server" Icon="Accept" Text="Log In">
                        <DirectEvents>
                            <Click Before="if(!#{txtUsername}.validate()||(!#{txtPassword}.validate()|| #{txtUsername}.disabled)){ #{myStatus}.Hide(); return false;}">
                                <ExtraParams>
                                    <ext:Parameter runat="server" Name="Resolution" Value="Ext.getBody().getViewSize()" Mode="Raw" Encode="True"></ext:Parameter>
                                </ExtraParams>
                                <EventMask Target="CustomTarget" CustomTarget="#{Window1}" Msg="Please wait..." ShowMask="True"></EventMask>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </Items>
    </ext:Container>
    What should I change to prevent clear textFiled.Text in txtLogin as well as txtPassword?

    Another question is there a way to bind a key to entire form?

    Thanks,
    ViDom
    Last edited by Daniil; May 09, 2013 at 1:39 PM. Reason: [CLOSED]
  2. #2
    Hi @ViDom,

    Seems nothing happens for me when I press Enter.

    Is the <mmp:StatusPanel> required to reproduce the problem?

    Also there is an excessive </ext:Button> tag. Please ensure the code snippet is runnable.

    Please describe steps to reproduce.

    Quote Originally Posted by ViDom View Post
    Another question is there a way to bind a key to entire form?
    I would try tp configure a Container's KeyMap property.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ViDom,

    Seems nothing happens for me when I press Enter.

    Is the <mmp:StatusPanel> required to reproduce the problem?

    Also there is an excessive </ext:Button> tag. Please ensure the code snippet is runnable.

    Please describe steps to reproduce.



    I would try tp configure a Container's KeyMap property.

    Thanks and sorry for inconvienient @Daniil I was out of forum for quite a long time (forgot about making usefull samples) :)
    Could you please provide sample of configure KeyMap property for ENTER keycode?
    I've just try my code in sample and it works but on production enviroments it's not work. I will investigate and let you know if find problem.
  4. #4
    Example
    <ext:FormPanel runat="server">
        <Items>
            <ext:TextField runat="server" />
            <ext:TextField runat="server" />
        </Items>
        <KeyMap runat="server">
            <Binding>
                <ext:KeyBinding Handler="alert('Enter');">
                    <Keys>
                        <ext:Key Code="ENTER" />
                    </Keys>
                </ext:KeyBinding>
            </Binding>
        </KeyMap>
    </ext:FormPanel>
    Please clarify what do you need to do on Enter?
  5. #5
    Quote Originally Posted by Daniil View Post
    Example
    <ext:FormPanel runat="server">
        <Items>
            <ext:TextField runat="server" />
            <ext:TextField runat="server" />
        </Items>
        <KeyMap runat="server">
            <Binding>
                <ext:KeyBinding Handler="alert('Enter');">
                    <Keys>
                        <ext:Key Code="ENTER" />
                    </Keys>
                </ext:KeyBinding>
            </Binding>
        </KeyMap>
    </ext:FormPanel>
    Please clarify what do you need to do on Enter?
    I would like a fireEvent 'click' of LoginButton I'had write like this:
    <script runat="server">
           protected void LoginButtonClick(object sender, DirectEventArgs e)
           {
                  Ext.Net.X.Msg.Alert("alert","alert!").Show();
           }
    </script>
    <ext:FormPanel runat="server">
        <Items>
            <ext:TextField runat="server" />
            <ext:TextField runat="server" />
            <ext:Button runat="server" ID="LoginButton">
                   <DirectEvents>
                        <Click OnEvent="LoginButtonClick"/>
                   </DirectEvents>
             </ext:Button>
        </Items>
        <KeyMap runat="server">
            <Binding>
                <ext:KeyBinding Handler="e.stopEvent();#{LoginButton}.fireEvent('click');">
                    <Keys>
                        <ext:Key Code="ENTER" />
                    </Keys>
                </ext:KeyBinding>
            </Binding>
        </KeyMap>
    </ext:FormPanel>
    Am I doing something wrong?
  6. #6
    Please try to set up
    DefaultButton="LoginButton"
    for the FormPanel instead of a KeyMap.
  7. #7
    Quote Originally Posted by Daniil View Post
    Please try to set up
    DefaultButton="LoginButton"
    for the FormPanel instead of a KeyMap.
    It's do the work:)
    Thanks @Daniil:) Thread can be closed.

Similar Threads

  1. [CLOSED] Window with textfield is posting on enter
    By SouthDeveloper in forum 1.x Premium Help
    Replies: 1
    Last Post: Nov 05, 2012, 7:50 PM
  2. Clear Controls (textfield)
    By Maia in forum 1.x Help
    Replies: 4
    Last Post: Feb 02, 2012, 11:00 AM
  3. Replies: 4
    Last Post: Oct 10, 2011, 4:28 PM
  4. [1.0] Splitbutton and keyboard usage
    By plykkegaard in forum 1.x Help
    Replies: 0
    Last Post: Feb 14, 2011, 11:36 AM
  5. Replies: 8
    Last Post: Apr 28, 2010, 4:20 PM

Tags for this Thread

Posting Permissions