使用itemEditor在flex数据网格中验证 [英] validation in flex datagrid using itemEditor
问题描述
pre $
< mx:DataGridColumn headerText =Value
dataField =Values
width =100
editable ={!this.areVariablesReadOnly}>
< mx:itemEditor> < MX:成分> < mx:TextInput restrict =0-9maxChars =3/> < / MX:成分> < / MX:的itemEditor>
< / mx:DataGridColumn>
这仅对int值验证值列的字段。现在,如果选择了字符,我需要使用不同的itemEditor以不同的方式进行验证。
简而言之,如果(int)
使用ItemEditor1
else if(char)
使用ItemEditor2
否则if(condition)
使用Itemeditor3。
任何人都可以指向正确的方向吗?
dataChange
事件)会使你的例如,(假设你的数据类型字段是
type
) 在您的MXML中:
< mx:itemEditor>
< fx:Component>
< local:ValueInput type ={data.type}/>
< / fx:Component>
< / mx:itemEditor> b
$ Value Value $ > package
{
import mx.controls.TextInput;
$ b $ public class ValueInput extends TextInput
{
public function set type(value:String):void
{
switch(value)
{
casechar:
restrict = null;
break;
caseint:
restrict =0-9;
break;
casehex:
restrict =0-9A-F;
break;
$ b $ hr
然而,我不能说这是正确的方向。这只是一种做法。可以有许多其他创造性的方式,也取决于开发人员的编码风格。
你想要做什么也是一个好方法。实现MX组件需要更长的时间。
希望这有助于您。
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?
解决方案 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.
这篇关于使用itemEditor在flex数据网格中验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!