validation in flex datagrid using itemEditor

谁都会走 提交于 2019-12-25 02:53:25

问题


I have a datagrid which conatains two columns. Datatype and value. Datatype has a combobox with options like char, int, unsigned int, signed int etc.Now i want to have validation on what value is entered in value column. I am using following method .

<mx:DataGridColumn headerText="Value"
                               dataField="Values"
                               width="100"
                               editable="{!this.areVariablesReadOnly}">
            <mx:itemEditor> <mx:Component> <mx:TextInput restrict="0-9" maxChars="3" /> </mx:Component> </mx:itemEditor>
            </mx:DataGridColumn>

This validates value column's fields only for int values. Now if char is selected , i need to use different itemEditor to validate in a different way. In short,

   if (int)
          use ItemEditor1 
   else if (char)
      use ItemEditor2
   else if (condition)
      use Itemeditor3.

Can anybody point me in correct direction?


回答1:


The data property (and also dataChange event) will make your life easier.

For example,
(assuming that your Datatype field is type)

In your MXML:

<mx:itemEditor>
    <fx:Component>
        <local:ValueInput type="{data.type}"/>
    </fx:Component>
</mx:itemEditor>

ValueInput.as:

package
{
    import mx.controls.TextInput;

    public class ValueInput extends TextInput
    {
        public function set type(value:String):void
        {
            switch (value)
            {
                case "char":
                    restrict = null;
                    break;
                case "int":
                    restrict = "0-9";
                    break;
                case "hex":
                    restrict = "0-9A-F";
                    break;
            }
        }
    }
}

However, I can't say this is the "correct direction". It is just one way of doing it. There can be many other creative ways, and it also depends on developer's coding style.

What you were trying to do was also a fine way. It just takes a bit longer to implement for MX components.

Hope this helps.



来源:https://stackoverflow.com/questions/23232259/validation-in-flex-datagrid-using-itemeditor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!