2 Replies Latest reply on Jan 27, 2011 12:25 PM by jlanpheer

    Defaulting a value into a Form.

    jlanpheer

      Hi-

       

      I have a fairly simple business need which is to default a dynamic value into a form, but i'm not sure how to go about "properly" persisting the value within my Flex application.

       

      I have a main application page which contains two canvases.

      1) One with some controls for entering query parameters and a DataGrid which displays results based on the selections made and

      2) A form (actually a Farata Systems' DataForm, but the principles should be the same) which allows a user to either create a new record or update an existing one selected from the DataGrid.  This form scrolls into view "accordian-style" if the user presses a "Create" button in the canvas above or if the "Update" button is pressed for a specific record in the DataGrid.

       

      Basically, all i need to do is build some intelligence into the form in (2) above so that it defaults the value into a FormItem that was there the last time that i was in the form.  To illustrate, let's say that we are talking about a bank account number:  Let's say that i start a session and navigate to the form in (2) above by clicking the "Create" button canvas #1 above.  The first time i go there, the FormItem will default to "null" (because its the first time in).  Let's say that i fill out the form and enter a bank account number of '123'.  I save my changes and return to the canvas described in (1) above.  Now, i want to create another record and i again navigate to the form in (2) above.  This time, i want the the bank account number '123' that was there last time to default into the FormItem when it displays.  Of course, as a user i could change that to '456' if i wanted, and save that record.  If i returned a third time, i would want the FormItem to default to '456' when the canvas is displayed.

       

      The basic business need is to allow someone to enter multiple transactions and reduce keying by defaulting in certain values.  Basically, i am at a loss on how to "properly" persist the last entered value within the application.  Can anyone give me pointers on how to do this?  If the above English description doesn't clarify what i am doing well enough, i can provide some sample code, but i think this is clear enough......

      thanx and cheers!

      jim.

        • 1. Re: Defaulting a value into a Form.
          miguel8312 Level 3

          can you post your code up of perhaps put together a little project example. so that

          we  can help. If i understand this correctly when the application loads you would like to default some values on the form

          right?

          if that is the case then  let me ask you what sdk are you using..?

          post up and ill help you.

          Miguel

          • 2. Re: Defaulting a value into a Form.
            jlanpheer Level 1

            Thanks, I think you understand my problem correctly, so here's some code.  Note, i am using the Farata Systems' DataForm which is an extension of Form, so i think that treating any references to "DataForm" can be treated as "Form".  I am using the Java 1.5.0.7 JDK.

             

             

            Here's a portion of the script part:

            <mx:Script>
                <![CDATA[

                      import com.gwla.cs.au17.datasource.dto.detailDTO; // My DTO which populates a DataGrid.  I don't use this, but maybe i need to?

                      [Bindable]
                      public var defaultBankAcct:String;  // I am trying to persist the last value contained in the BANK_ACCT_NUM item from my DataForm

                                                                         // here for later use.

             

                      private function resetDataForm():void {
                          ac.selectedIndex=0;  // Navigates back to the main page containing the DataGrid.  "ac" refers to the accordian canvas that contains the DataForm.
                          updateForm.dataProvider = null;  // Clears the DataForm.
                          defaultBankAcct = updateForm.BANK_ACCT_NUM;  //  ?? This line is one of my two problems, i don't know how to persist the value from the

                                                                                                      //   DataForm to this variable.  This does not work, but it says logically what i am trying to do.

                                                                                                      // Maybe i need to pass the DTO to this function, but i get syntax errors.
                      }

             

            There are two canvases:  One which has some controls to enter search criteria and display the results in a DataGrid.  It also has a control "Create" which allows a user to scroll down on the page to enter a new record.  If the user clicks "Create" or an "Update" control on the DataGrid, the DataForm described below scrolls into view either as an empty form (in the "Create" case) or with the complete record from the DataGrid (in the "Update" case).  Control is returned back to this canvas when the user is done with the DataForm below.  I can include code of this if necessary, but its not really applicable to my problem.

             

            This is the second canvas that gets scrolled to if the user wants to either enter a new record or update an existing one.

            This is a little HBox with a couple of controls in it.  "Save Changes" commits the values in the DataForm to the DataGrid, and that works.  "Back" takes me to another canvas on the same page.  When the user presses the "Back" button, i am trying to save the value of the BANK_ACCT_NUM (in this example), so that if the user were to return to the DataForm again, the BANK_ACCT_NUM from the last entry would be defaulted.

             

            <mx:Canvas height="100%" width="80%" horizontalScrollPolicy="off">
                <mx:Panel id="childPanel" height="100%" width="100%">

                <mx:HBox  paddingLeft="30" horizontalAlign="left" width="100%">
                      <mx:Button enabled="{collection.commitRequired}" click="doUpdate()" label="Save Changes"/>

                      <mx:Button click="resetDataForm()" label="Back"/>
                </mx:HBox>

             

            <!-- This is the DataForm.  All i am trying to do is default the BANK_ACCT_NUM value from the last time the user was in the DataForm if the user comes back.  If its the first time in, i want the value of the DataFormItem to be blank (which it is currently doing).  My second (possible) problem is that i don't know if "preinitialize" in the definition of the DataFormItem (read "FormItem") will default the value or not, i haven't gotten to that point yet. -->

            <mx:HBox>
                    <fx:DataForm initialize="initArray()" id="updateForm" dataProvider="{detailDG.selectedItem}">
                        <fx:DataFormItem dataField="BANK_ACCT_NUM" readOnly="{this.isNew}" preinitialize="{this.defaultBankAcct}" label="Bank Acct Num:"/>
            </mx:HBox>

                </mx:Panel>
            </mx:Canvas>

             

            If you need more code to clarify the understanding of my problem, please let me know.

            thanx and cheers!

            jim.