It is a Common requirment that, We might clear the fields during Search and Submit Use Cases. Instead of writing Screeen specific Code, We can write a utility that can clear the fields by iterating through the component Hierarchy.
Remember, The Logic to clear the field ( Combobox, Text Input etc ) is specific to your Usecase. For E.g, This Demo application, will clear the Data Provider of a Combo Box, But as per your Project, You may need to select the first Item of the Dataprovider during the clear Operation.
So You can customize the utility function
private function clearFields(rootContainer:Container):void
as per your need
Bellow is the Source Code:
/**
* rootContainer - Container from where we have to start clearing the fields
*
* TO USE: clearFields(searchPane) ;
*/
private function clearFields(rootContainer:Container):void {
for each ( var child:UIComponent in rootContainer.getChildren() ) {
// If Container Found, Get into the new Container's Hierarchy
if(child is Container) {
clearFields(Container(child)) ;
}
else {
// This is the Place where you can have the clear Logic for the components that u use
if(child is TextInput) {
TextInput(child).text = '' ;
}
else if(child is CheckBox) {
CheckBox(child).selected = false ;
}
else if(child is ComboBox) {
ComboBox(child).dataProvider = null ;
}
else if(child is List) {
List(child).dataProvider = null ;
}
else if(child is DataGrid) {
DataGrid(child).dataProvider = null ;
}
else if(child is DateField) {
DateField(child).selectedDate = null ;
}
}
}
}
1 comment:
Thanks Sathish for ur sample
Post a Comment