8 Replies Latest reply on Dec 3, 2010 12:39 AM by vineet osho

    Simple DataGrid validation Problem

    vineet osho

      hi friends

                     I am working on a application in which i  m facing a problem.i have a datagrid having two column field one is simple datagrid column and in other  datagrid column i render textinput as a component. there are only two row in my datagrid.so now i have to apply validation on that data grid.i mean if any textinput componet which is render in second column in data grid left blank and i click on save button then there should be validation Alert messg.

      i am facing a problem on gettin id(instance) of that two rendered textinput component.Please help me out.

       

      Thanks and Regards

         Vineet Osho

        • 1. Re: Simple DataGrid validation Problem
          Flex harUI Adobe Employee

          Usually, the renderers are backed by data in the dataProvider and scanning

          through that data is the recommended way.

          1 person found this helpful
          • 2. Re: Simple DataGrid validation Problem
            vineet osho Level 1

            Hi sir

                      thanks for such a quick reply. i am not getting wot u want to say.i just need instance of rendrerd componet which is always 2 in count and they are Textinput.i just want to check on some button click outside my datagrid that wether that textinput are filled or not.i mean i have to apply vaidation on that rendred two textinput component.

             


            Waiting for reply

               Vineet Osho

            • 3. Re: Simple DataGrid validation Problem
              Flex harUI Adobe Employee

              Renderers get recycled so someday if you have more rows, your validation

              will fail.

               

              Hopefully the TextInputs display data from some field in the dataProvider so

              scanning the dataProvider for objects whose field is empty should be the

              equivalent, faster, and safe from recycling issues.

              1 person found this helpful
              • 4. Re: Simple DataGrid validation Problem
                vineet osho Level 1

                Hi sir

                         Actually there are not any data provider in this case.i use textinput component as a rendrer because user enter text in that componet and saved it on save button click.if both textinput fields are not filled.then i need validation messg.hope you got want i want to say.i know its a simple logical problem but i cant getting  any clue for this.so please help me out.and there is not any data in that rendred text input component we have to add the data in that part.

                 

                 

                Regards

                Vineet osho

                • 5. Re: Simple DataGrid validation Problem
                  BhaskerChari Level 4

                  Hi Vineet osho,

                   

                  What Alex is saying is you can loop through the dataProvider for your DataGrid instead of having a check based on TextInput ids...Its not a reliable way of approaching it since the renderers gets recycled.

                   

                  Can you post the code you are working so that I will make you clear..

                   

                  Thanks,

                  Bhasker

                  • 6. Re: Simple DataGrid validation Problem
                    vineet osho Level 1

                    Hi bhasker

                                     please check this code.and reply me soon.i need a method that tell me weather text in textinput rendrer component is blank or having some values.

                     

                          <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                        >
                        <mx:Script>
                            <![CDATA[
                                import mx.controls.TextInput;
                                import mx.events.DataGridEvent;
                                import mx.controls.Alert;
                                public var arr:Array = [];
                                public  var incrementer:int;
                            ]]>
                        </mx:Script>
                        <mx:DataGrid horizontalCenter="0" verticalCenter="0" width="400" height="200" >
                            <mx:columns>
                                <mx:DataGridColumn headerText="First" width="60" dataField="artist"/>
                                 <mx:DataGridColumn   width = "60" headerText = "Premium %(e.g. Percentage as 100)" >
                                       <mx:itemRenderer>
                                            <mx:Component>
                                                 <mx:TextInput  styleName="TextInputRight" width = "100">
                                                 </mx:TextInput>
                                            </mx:Component>
                                        </mx:itemRenderer>
                                  </mx:DataGridColumn>
                           </mx:columns> 
                                  <mx:dataProvider>
                                    <mx:ArrayCollection>
                                      <mx:Array>
                                        <mx:Object title="Stairway to Heaven" artist="Led Zepplin"/>
                                        <mx:Object title="How to Save a Life" artist="Fray"/>
                                      </mx:Array>
                                    </mx:ArrayCollection>
                                  </mx:dataProvider>
                          </mx:DataGrid> 
                          <mx:Button id="btn" label="click"  x="527" y="418" />
                    </mx:Application>

                     

                     

                    Thanks in advance

                      Vineet osho

                    • 7. Re: Simple DataGrid validation Problem
                      BhaskerChari Level 4

                      Hi Vineet Osho,

                       

                      You can try this...

                       

                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                          >
                          <mx:Script>
                              <![CDATA[
                               import mx.utils.StringUtil;
                               import mx.collections.ArrayCollection;
                                  import mx.controls.TextInput;
                                  import mx.events.DataGridEvent;
                                  import mx.controls.Alert;
                                  public var arr:Array = [];
                                  public  var incrementer:int;
                                 
                                  private function validateTextInputs():void
                                  {
                                   var strIndexes:String="";
                                   var gridDP:ArrayCollection = dataGrid.dataProvider as ArrayCollection;
                                   for(var i:int=0;i<gridDP.length;i++)
                                   {
                                    if(StringUtil.trim(gridDP.getItemAt(i).displayText) == "")
                                    {
                                     strIndexes += (i + 1) + ",";
                                    }
                                   }
                                   if(strIndexes.length > 0)
                                   {
                                    strIndexes = strIndexes.substring(0,strIndexes.length-1);
                                    Alert.show("The TextInputs " + strIndexes + " are empty.");
                                   }
                                  }
                              ]]>
                          </mx:Script>
                          <mx:DataGrid id="dataGrid" horizontalCenter="0" verticalCenter="0" width="400" height="200">
                              <mx:columns>
                                  <mx:DataGridColumn headerText="First" width="60" dataField="artist" editable="false"/>
                                   <mx:DataGridColumn   width = "60" headerText = "Premium %(e.g. Percentage as 100)" >
                                         <mx:itemRenderer>
                                              <mx:Component>
                                                   <mx:TextInput styleName="TextInputRight" focusOut="data.displayText=this.text;" width="100" text="{data.displayText}">
                                                   </mx:TextInput>
                                              </mx:Component>
                                          </mx:itemRenderer>
                                    </mx:DataGridColumn>
                             </mx:columns> 
                                    <mx:dataProvider>
                                      <mx:ArrayCollection>
                                        <mx:Array>
                                          <mx:Object title="Stairway to Heaven" artist="Led Zepplin" displayText=""/>
                                          <mx:Object title="How to Save a Life" artist="Fray" displayText=""/>
                                        </mx:Array>
                                      </mx:ArrayCollection>
                                    </mx:dataProvider>
                            </mx:DataGrid> 
                            <mx:Button id="btn" label="click"  x="527" y="450" click="validateTextInputs()" />
                      </mx:Application>

                       

                       

                      Thanks,

                      Bhasker

                      • 8. Re: Simple DataGrid validation Problem
                        vineet osho Level 1

                        Thanks a ton bhasker.u again resolved my issue.