Reputation: 31
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?
Upvotes: 0
Views: 257
Reputation: 389
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.
Upvotes: 0