8 Replies Latest reply on Sep 10, 2007 11:15 AM by Peter deHaan

    Help with form controls

    Barb
      I have a Flex/Air project that is to be an offline form that will store data input until a network connection is established. I'm stuck on properly storing the values of radiobuttons, comboxes, checkboxes, and list form controls.

      I've attached the pertinent code and provide a synopsis of the problems I'm encoutering here:

      Radiobuttons - RadioButtonGroup id-"relevance: using "selectedValue" to retrieve form value, but coming through as NULL.
      Comboboxes - ComboBox id="apply_term0": using "selectedLabel" (selectedValue throws an error) which pulls in the label, but not the data.
      Lists - List id="majors": can't find any parameter that doesn't throw an error
      Checkboxes - CheckBox id="??": can't find any parameter that doesn't throw an error. Also, I'd like to structure this similar to a RadioButtonGroup, where I have a handful of checkboxes that are identically named and the the value that is passed through for that form field is a comma-delimited list of values of the options that were checked (like HTML).

      Any assistance you can provide is greatly appreciated!

        • 1. Re: Help with form controls
          Yukari M Level 1
          Hi Barb,

          As to RadioButtonGroup, no idea why selectedValue returns null. Is one of RadioButtons selected when addInquiryHandler() gets called?

          For ComboBox, have you tried something like combobox.selectedItem.data? Same for List, try list.selectedItem.label or list.selectedItem.data.

          CheckBox doesn't have built-in grouping class like RadioButtonGroup so please read "selected" property of each CheckBox to determine if it is selected.

          HTH,

          -Yukari
          • 2. Re: Help with form controls
            Barb Level 1
            One step closer, thanks to Yukari.

            I used applyterm_0.selectedItem.data to retrieve the value form the term COMBOXBOX and it worked!

            But, that same syntax did not work for the LIST. I tried majors.selectedItem.data and it threw an error "Error #1009: Cannot access a property or method of a null object reference." even though I verified that items were selected. I then tried majors.selectedItem.data, which did not throw an error, but saved nothing to the database despite items being selected.

            No luck with the RADIOBUTTONS (or the CHECKBOXES) - so far selectedValue doesn't work for either (pulls in NULL).

            Any other suggestions are appreciated! Thanks, BJS
            • 3. Re: Help with form controls
              Barb Level 1
              I am completely at a loss on this one. I am at a point where the values of two groups of RADIOBUTTONS are retrievable, but the one that I was originally working still is not . . . along with the LIST, which happens to be in the same section of code. I'm copying the code here in it's entirety (warts and all) in case someone has an interest in reviewing it to see what I'm doing wrong.

              Note that I did get the CHECKBOX values to come through. This was a situation where I had set the ID parameter for the checkboxes, but not the NAME. Once I changed this, the values came through without a problem.

              • 4. Re: Help with form controls
                Barb Level 1
                I fixed my problem with the relevance RADIOBUTTONS by including the items within <formitem></formitem> tags.

                Still struggling with the List. I'm trying to get to the data using majors.selectedItems.data, which doesn't throw an error but comes up blank (not NULL, just blank). If anyone can help me retrieve the data from a multiple-select List, I would be forever grateful.
                • 5. Re: Help with form controls
                  Barb Level 1
                  OK, I can get the LIst to work if I don't allow multiple selections, so basically the only thing I have yet to do is figure out how to retrieve the data for the LIST control if I allow multiple selections.
                  • 6. Re: Help with form controls
                    Peter deHaan Level 4
                    Barb,

                    I can get the selected items from a multiselect list in the following snippet, but I'm not sure that you can use the "myList.selectedItems.data" syntax since selectedItems returns an array...

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
                    layout="vertical"
                    verticalAlign="middle"
                    backgroundColor="white">

                    <mx:XML id="majors">
                    <obj>
                    <item>
                    <data>bio_mph_cur</data>
                    <label>Biostatistics MPH</label>
                    </item>
                    <item>
                    <data>bio_ms_cur</data>
                    <label>Biostatistics MS</label>
                    </item>
                    <item>
                    <data>bio_phd_cur</data>
                    <label>Biostatistics PhD</label>
                    </item>
                    <item>
                    <data>cr_ms_cur</data>
                    <label>Clinical Research MS</label>
                    </item>
                    <item>
                    <data>che_mph_cur</data>
                    <label>Community Health Educ. MPH</label>
                    </item>
                    </obj>
                    </mx:XML>

                    <mx:List id="list"
                    allowMultipleSelection="true"
                    dataProvider="{majors.item}" />

                    <mx:List id="list2"
                    dataProvider="{list.selectedItems}" />

                    </mx:Application>

                    If you need to grab all the all the "data" nodes for the selected items, I'd probably just recommend looping over each item in the selectedItems array.

                    Peter
                    • 7. Re: Help with form controls
                      Barb Level 1
                      Peter -

                      Thanks! This is what I did for my insert statement and it works great:

                      // Add a new inquiry.
                      private function addInquiryHandler():void
                      {

                      // create the SQL statement
                      var insertStmt:SQLStatement = new SQLStatement();
                      insertStmt.sqlConnection = conn;

                      // new stuff based on Peter's post:
                      var majors_selected:String;
                      for each(var tempobject:Object in majors.selectedItems){
                      majors_selected = majors_selected + tempobject.data + "/";
                      }

                      // define the SQL text
                      var sql:String =
                      "INSERT INTO inquiry " +
                      "(firstName," +
                      "lastName," +
                      "dateofbirth, " +
                      "undergrad, " +
                      "undergrad_school, " +
                      "graduate, " +
                      "interest_level, " +
                      "interest_level_other, " +
                      "apply_term, " +
                      "email, " +
                      "phone, " +
                      "street1, " +
                      "street2, " +
                      "street3, " +
                      "city, " +
                      "state_id, " +
                      "zip, " +
                      "country_id, " +
                      "majors, " +
                      "mail_info_sheets, " +
                      "mail_catalog, " +
                      "message, " +
                      "events, " +
                      "newsletter, " +
                      "bio " +
                      ") " +
                      "VALUES " +
                      "('"+firstnameValid.text+"', '"
                      +lastnameValid.text+"', '"
                      +birthmonthValid.selectedItem.data+"/"+birthdateValid.selectedItem.data+"/"+birthyearVali d.selectedItem.data+"', '"
                      +major_undergrad0.text+"', '"
                      +college0.text+"', '"
                      +degrees0.text+"', '"
                      +relevance.selectedValue+"', '"
                      +relevance_other.text+"', '"
                      +apply_term0.selectedItem.data+"', '"
                      +emailValid.text+"', '"
                      +phone.text+"', '"
                      +street1.text+"', '"
                      +street2.text+"', '"
                      +street3.text+"', '"
                      +city.text+"', '"
                      +state_id.selectedItem.data+"', '"
                      +zip.text+"', '"
                      +country_id.selectedItem.data+"', '"
                      +majors_selected+"', '"
                      +mail_info_sheets.selectedValue+"', '"
                      +mail_catalog.selectedValue+"', '"
                      +question.text+"', '"
                      +events1.selected+"/"+events2.selected+"/"+events3.selected+"/"+events.selected+"', '"
                      +newsletter.selected+"', '"
                      +bio.text+"')";
                      insertStmt.text = sql;

                      • 8. Re: Help with form controls
                        Peter deHaan Level 4
                        Barb,

                        Good work! A word of caution, looking at your code it looks like you'll always have an extra trailing "/" in your majors_selected string:
                        [quote]
                        // new stuff based on Peter's post:
                        var majors_selected:String;
                        for each(var tempobject:Object in majors.selectedItems){
                        majors_selected = majors_selected + tempobject.data + "/";
                        }
                        [/quote]

                        If you want a cheap-ish workaround, you could always create a temporary array and then use the "join()" method to convert the array into a string, like so:
                        [code]
                        // new stuff based on Peter's post:
                        var majors_selected:String;
                        var tempArr:Array = [];
                        for each(var tempobject:Object in majors.selectedItems){
                        tempArr.push(tempobject.data);
                        }
                        majors_selected = tempArr.join("/");
                        [/code]

                        Happy Flexing!

                        Peter