7 Replies Latest reply on Oct 18, 2006 8:58 AM by leotemp

    Default  Button doesn't work

    dimival Level 1
      I am using a form and trying to put a default button by using the defaultButton property but it doesn't work, is there anything else i need to do?
        • 1. Re: Default  Button doesn't work
          leotemp Level 1
          Here is a working example of the default button in a form I know youve been asking for this for awhile, sorry.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">

          <mx:Script>
          <![CDATA[
          import BlackMesa.UI;

          function printInput():void
          {
          labelResult.text= tiInput.text.toString();
          }
          ]]>
          </mx:Script>
          <mx:Form x="554" y="251" width="250" height="250" defaultButton="{buttonDefault}">
          <mx:FormItem label="Label">
          <mx:TextInput id="tiInput"/>
          </mx:FormItem>
          <mx:FormItem id="buttonSubmit">
          <mx:Button label="Button" click="{printInput()}" id="buttonDefault"/>
          </mx:FormItem>
          <mx:FormItem label="Label">
          <mx:Label text="input" id="labelResult"/>
          </mx:FormItem>
          </mx:Form>
          </mx:Application>

          The concept here is add all the functionality to the button control, give it an ID, then in your form you just call the button through the defaultButton property and it executes everything associated with the button control, make sure when you specify the button to use that you specify the {object}, hope the example above helps, i tested it before posting.
          • 2. Default  Button doesn't work
            dimival Level 1
            Yes i know how it works, but it doesn't, i type into a textInput control and then I press Enter and nothing happens, here's my code:

            <mx:Form height="10%" defaultButton="{busquedaBoton}">
            <mx: FormItem direction="horizontal" label="@Resource(bundle='SeguridadFlex', key='nombre')"/>
            <mx:TextInput id="nombreBusqueda" change="CatalogUtils.toUpperCase(event)" maxChars="20"/>
            <mx:Button id="busquedaBoton" label="@Resource(bundle='SeguridadFlex', key='buscar')" click="ctrl.actionSearchCatalog(nombreBusqueda.text, sistemaBusqueda.text)"/>
            </mx:FormItem >
            </mx:Form>

            Like i said, when i type into the TextInput and then press enter nothing happens
            • 3. Re: Default  Button doesn't work
              leotemp Level 1
              huh, i dont know what to tell you, i thourouly tested my posted example and was able to execute functions just fine by only typing in the textbox and pressing the enter key on my keyboard, the example itself uses a function to post your input in the textbox to a label and as i said works fine, if it doesnt work for you then i suggest that perhaps it is something else in your application.

              Your posted example has a few errors in it but I know alot of people post stuff on the fly and it might not be a good example of your application. I would be really surprised if my above example didnt work on its own.

              Here is a corrected version of the application snippet you posted above:

              <mx:Form height="10%" defaultButton="{busquedaBoton}">

              <mx:FormItem direction="horizontal" label="@Resource(bundle='SeguridadFlex', key='nombre')">
              <mx:TextInput id="nombreBusqueda" change="CatalogUtils.toUpperCase(event)" maxChars="20"/>
              <mx:Button id="busquedaBoton" label="@Resource(bundle='SeguridadFlex', key='buscar')" click="ctrl.actionSearchCatalog(nombreBusqueda.text, sistemaBusqueda.text)"/>
              </mx:FormItem >

              </mx:Form>

              The two errors that caught my eye were 1] you had a space char in "<mx: FormItem" it should be "<mx:FormItem" 2] this same tag, FormItem was closed and then a coresponding closed FormItem tag was below, i removed the first "/" at the end of your first "FormItem" tag and now your example validates. When you have errors like that flex wont compile your app so you can be under the impression that your making changes and your changes arent being reflected. Anyways, give that a shot and if it fails try working backwards from my example which i just tested again and it works :)

              Good Luck!
              • 4. Re: Default  Button doesn't work
                dimival Level 1
                Those mistakes were made when i typed the snippet. It still doesn't work, as a matter of fact, whenever I type into de TextInput the button is highlighted, which i assume indicates that button is the default one, but if i press the Enter key it doesn't do anything.

                Any ideas?
                • 5. Re: Default  Button doesn't work
                  leotemp Level 1
                  Are you pasting my entire application snippet as an entire application and then compiling it as is? I just cant understand how it can work for me but not you. Are you using flex builder or the SDK? If you like i can compile my app, and post it online for you to look at it and throw the source up along side it. I just copied my snippet and compiled it and it works for me.. Do you have the newest version of flash? If you havent updated since the beta that could be a problem..
                  • 6. Re: Default  Button doesn't work
                    dimival Level 1
                    Funny thing is that i tried in another application and it worked, the same way i have it, maybe something on my app is causing the error, who knows.
                    • 7. Re: Default  Button doesn't work
                      leotemp Level 1
                      well, you could post your entire app, and let us take a look, other then that Im not sure what else can be done.