3 Replies Latest reply on Oct 5, 2009 10:38 AM by Flex harUI

    enable ENTER key for submitting forms

    Alex-SM Level 1



      Is there an easy way beside the following way to enable ENTER key for submitting forms in Flex. I am looking for a way to enable ENTER key (along with MOUSE click) for ALL buttons in an application.




                  public function init():void{
                   public function submit():void{
                   function checkKey(event:KeyboardEvent):void
                       if(event.charCode == 13)


      <mx:LinkButton label="Submit"  click="submit();" />    

        • 1. Re: enable ENTER key for submitting forms
          Gregory Lafrance Level 6

          As this app shows, just set the container defaultButton property. User must at least change focus to the container sub-controls though.


          If this post answers your question or helps, please mark it as such.


          <?xml version="1.0"?>
          <!-- containers\intro\ContainerDefaultB.mxml -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                      public function submitLogin():void {
                          text1.text="You just tried to log in.";

              <mx:Panel title="Default Button Example">

                  <mx:Form defaultButton="{mySubmitBtn}">
                      <mx:FormItem label="Username:">
                          <mx:TextInput id="username" width="100"/>
                      <mx:FormItem label="Password:">
                          <mx:TextInput id="password" width="100" displayAsPassword="true"/>
                          <mx:LinkButton id="mySubmitBtn" label="Login" click="submitLogin();"/>
                  <mx:Text id="text1" width="150"/>

          • 2. Re: enable ENTER key for submitting forms
            Alex-SM Level 1

            thanks for the replay. But my containers has multiple buttons, for instance the login popup has "login" and "cancel" buttons.

            Can I set multiple IDs inton the "defaultbutton" property of the container?



            • 3. Re: enable ENTER key for submitting forms
              Flex harUI Adobe Employee

              Standard UI has only one defaultButton per popup.  However, if the user tabs to other buttons in the popup, then ENTER will activate those buttons instead.


              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui