Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using validators in DataGrid - Flex

i have an editable DataGrid, something like:

<mx:Datagrid editable="true" dataProvider="{arrayListPreferences}" id="preferencesGrid">
    <mx:columns>
        <mx:DataGridColumn header="col1" dataField="preference" editable="false"/>
        <mx:DataGridColumn header="col2" dataField="value" editable="true"/>
    </mx:columns>
</mx:Datagrid>

When the user edits the data there's a button that he clicks and calls a function that saves the data to a database, and in this function i have to validate the data before sending it. I want to use simple validators (NumberValidator, StringValidator, etc) but i don't know how to set the source of this validators to the specified rows in the second column.

like image 970
Thiago Valle Avatar asked Dec 05 '09 17:12

Thiago Valle


2 Answers

<mx:NumberValidator source="{preferencesGrid.selectedItem}" property="value" 
    integerError="Enter Integer value"
    minValue="18" maxValue="50" domain="int" 
    trigger="{saveButton}" triggerEvent="click"
    valid="saveData();"/>

Set the property of validator to the dataField of the desired column.

like image 149
Amarghosh Avatar answered Oct 16 '22 03:10

Amarghosh


<mx:DataGridColumn editable="true" itemRenderer="MyTextInputItemRenderer"/>



public class MyTextInputItemRenderer extends TextInput{
        private var validator:StringValidator;
        public function MyTextInputItemRenderer(){
            validator = new StringValidator;
            validator.minLength=0;
            validator.property = "text";
            validator.source = this;
        }
        override public function set data(value:Object):void{
            super.data = value;
            validator.validate();
        }
    }
like image 33
Vijay Anand Mareddy Avatar answered Oct 16 '22 04:10

Vijay Anand Mareddy