3 Replies Latest reply on Sep 11, 2008 5:26 PM by zakel

    Collecting Form Values -- This should be easy!

    zakel
      I have a application that creates form elements dynamically from xml. (text, date, combobox, checkbox, radio). I am trying to collect id/values from an object. This code works fine until it reaches a non-text element like checkbox or radiobutton.

      I get this error: "Property text not found on mx.controls.CheckBox and there is no default value."

      How show I treat non-text formItems?

      This is the function that I have:

      private function collectFormValues():Object {
      var vals:Object = new Object();
      var items:Object = userInfoForm.getChildren();

      for (var i:int = 0; i < items.length; i++)
      {
      var item = items .getChildren();
      vals[item[0].name] = item[0].text;
      }

      return vals;
      }

      Thanks for any help !!!

      ------------------------------------------------------------------------------------------ --------------------------

      Application URL: http://www.i-codedesign.com/dynform/etouch_form_2.html

      Full Code + xml below if needed.



      null Application URL
        • 1. Re: Collecting Form Values -- This should be easy!
          Gregory Lafrance Level 6
          You are right, this is an easy post to answer. Each Flex component has properties (and styles, events, methods, etc.) that are associated with that type of control.

          So a CheckBox does not have a text property. It has a label property.

          You need to ensure your code creates each UI element appropriately, using only those properties that each type of control actually has. The API will guide you on that.
          • 2. Re: Collecting Form Values -- This should be easy!
            Level 7

            "zakel" <webforumsuser@macromedia.com> wrote in message
            news:ga6tkg$ark$1@forums.macromedia.com...
            >I have a application that creates form elements dynamically from xml.
            >(text,
            > date, combobox, checkbox, radio). I am trying to collect id/values from an
            > object. This code works fine until it reaches a non-text element like
            > checkbox
            > or radiobutton.
            >
            > I get this error: "Property text not found on mx.controls.CheckBox and
            > there
            > is no default value."
            >
            >
            > This is the function that I have:
            >
            > private function collectFormValues():Object {
            > var vals:Object = new Object();
            > var items:Object = userInfoForm.getChildren();
            >
            > for (var i:int = 0; i < items.length; i++)
            > {
            > var item = items .getChildren();
            > vals[item[0].name] = item[0].text;
            > }
            >
            > return vals;
            > }


            Check to see if item[0] is CheckBox and if so, look at selected instead of
            text.


            • 3. Re: Collecting Form Values -- This should be easy!
              zakel Level 1
              This works well....


              public function collectFormValues():Object
              {
              var vals:Array = new Array();
              var items:Object = userInfoForm.getChildren();

              for (var i:int = 0; i < items.length; i++) // looping around formitem elements
              {
              var item:Array = items .getChildren(); // get the children of the formitem

              for (var j:int = 0; j < item.length; j++) // looping around the controls contained in the formitem
              {
              if(item[j].toLocaleString().indexOf("TextInput") > -1 || item[j].toLocaleString().indexOf("TextArea") > -1 ||
              item[j].toLocaleString().indexOf("DateField") > -1)
              {
              vals.push(item[j].id + "=" + item[j].text);
              }
              else if(item[j].toLocaleString().indexOf("CheckBox") > -1 || item[j].toLocaleString().indexOf("RadioButton") > -1)
              {
              vals.push(item[j].id + "=" + item[j].selected);
              }
              else if(item[j].toLocaleString().indexOf("ComboBox") > -1)
              {
              vals.push(item[j].id + "=" + item[j].selectedLabel);
              }