6 Replies Latest reply on Mar 6, 2008 10:12 AM by bitwyse

    Looking for advice on creating forms

    bitwyse Level 1
      Currently, I am using code as shown below to create a read only version of a form for displaying information from my back end DB. I'm wondering is there an easy way to have single source for both read only and read write of a form? The idea, some users have read only access and some users have read/write access. I don't want to maintain two different forms.

      <mx:GridRow>
      <mx:GridItem/>
      <mx:GridItem>
      <mx:Label text="Primary Contact"/>
      </mx:GridItem>
      <mx:GridItem>
      <mx:Text text = "{_projectDetail.projectCompanyPrimContact}"/>
      </mx:GridItem>
      <mx:GridItem>
      <mx:Label text="Project Sponsor"/>
      </mx:GridItem>
      <mx:GridItem>
      <mx:Text text="{_projectDetail.projectCompanySponsors}"/>
      </mx:GridItem>
      </mx:GridRow>
        • 1. Looking for advice on creating forms
          Bryan Dresselhaus
          Here is a pseudo-code function:

          public function enable(container:Container, value:Boolean):void {
          for (var index:int = 0; index < container.getChildren().length; index++){
          try {
          UIComponent((container.getChildren() as Array)[index]).enabled = value;
          } catch (error:Error){}
          try {
          enable(Container((container.getChildren() as Array)[index]), value);
          } catch(error:Error){}
          }
          }


          You pass the id of your form or container object to the enable function and it will recursively navigate all the children and containers inside it disabling all the UIComponents.
          • 2. Re: Looking for advice on creating forms
            bitwyse Level 1
            So if I understand that correctly, your saying to use all textInput or textArea type fields and enable them when the user has edit access and disable them when the user is read only.

            I'm assuming if that is correct, the data still shows even if it's disabled???

            Thanks,

            STeveR
            • 3. Re: Looking for advice on creating forms
              Gregory Lafrance Level 6
              I think you would use TextInput as Text are not editable, and you would affect the editable property, not the enabled property. This app works though you need to figure out how to set the writeAccess variable for the user:

              <?xml version="1.0"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
              <mx:Script><![CDATA[
              import mx.controls.TextInput;
              [Bindable]
              private var projectCompanyPrimContact:String = "Fred Constantine";
              [Bindable]
              private var projectCompanySponsors:String = "Thomas Wilshire";

              private var writeAccess:Boolean = true;

              private function setAccess(event:Event):void{
              var txt:TextInput = TextInput(event.target);
              txt.editable = writeAccess;
              }
              ]]></mx:Script>
              <mx:Grid>
              <mx:GridRow>
              <mx:GridItem/>
              <mx:GridItem>
              <mx:Label text="Primary Contact"/>
              </mx:GridItem>
              <mx:GridItem>
              <mx:TextInput text = "{projectCompanyPrimContact}" creationComplete="setAccess(event)"/>
              </mx:GridItem>
              <mx:GridItem>
              <mx:Label text="Project Sponsor"/>
              </mx:GridItem>
              <mx:GridItem>
              <mx:TextInput text="{projectCompanySponsors}" creationComplete="setAccess(event)"/>
              </mx:GridItem>
              </mx:GridRow>
              </mx:Grid>
              </mx:Application>

              • 4. Looking for advice on creating forms
                Bryan Dresselhaus Level 1
                quote:

                Originally posted by: bitwyse
                So if I understand that correctly, your saying to use all textInput or textArea type fields and enable them when the user has edit access and disable them when the user is read only.

                I'm assuming if that is correct, the data still shows even if it's disabled???



                All UIComponent objects have an enabled field. So you could put comboBoxes, textInputs, buttons or any other controls in the form since they are all subclasses of the UIComponent class. If your user only has read access to the data, then you could use the function to disable all the controls by sending false. They'd still be able to read the values, just not change them.

                • 5. Re: Looking for advice on creating forms
                  bitwyse Level 1
                  That makes a lot of sense Greg. Thank you very much!

                  This is why I love this forum. You get a wide array of great ideas!!!!!

                  Thank you all very much!

                  STeveR
                  • 6. Re: Looking for advice on creating forms
                    bitwyse Level 1
                    OK, I have not even thought about the different data types outside off TextInput and TextArea.

                    Hmmm it seems the best way to do this might be to combine both ideas. I like the idea of calling a set access function on specific fields, since in my application, I have a mix of editable and non editable fields. Rather than setting all of them at once, I can set them as needed.

                    Thank you both very much for all the great ideas!!!!