--- In [email protected], "donvoltz" <[EMAIL PROTECTED]> wrote:
>
> Thanks for your help. I do not know why I thought updating a text
> field would automatically update the VO object. Your help is greatly
> appreciated. One more quick question about this, what is the best
> practice, to add the text fields to the value object when the form is
> submitted (button clicked) or to set up individual functions once each
> text field is changed?? I presented just a small portion of my form,
> in actuality I have about 35 fields that will contain user information
This is really strange. I have pretty much exactly the same as you,
where I have a ContactDetails object that has a firstName property that
is bound to a textInput field's text property, and when I type into the
field, it sets exactly as intended. My class structure is that
ContactDetails has a constructor that inits all the properties. The
firstName property has both a getter and setter, and it is of a data
type that is also a custom class, DataItem. DataItem has a constructor
that sets it up with default values, and each property has a getter and
setter.
Here are my classes in case you find them useful:
package com.magnoliamultimedia.vo
{
[Inspectable]
[Bindable]
public class ContactDetails
{
import com.magnoliamultimedia.vo.DataItem;
private var _fn:DataItem;//first name
private var _ln:DataItem;//last name
private var _country:DataItem;
private var _eMail:DataItem;
private var _phone:DataItem;
private var _aff:DataItem;//affiliation
private var _more:DataItem;
private var _allValid:Boolean;
public function ContactDetails(fn:String='',
ln:String='', c:String='', e:String='', p:String='', aff:String='',
m:String=''){
_fn=new DataItem(fn, 3, 50, true);
_ln=new DataItem(ln, 3, 50, true);
_country=new DataItem(c, 3, 50, true);
_eMail=new DataItem(e, 3, 50,
true, 'EMailValidator');
_phone=new DataItem(p, 7, 50);
_aff=new DataItem(aff, 0, 50);
_more=new DataItem(m, 0, 255);
}
public function get firstName():*{
return _fn;
}
public function set firstName(s:*):void{
if (s is String){
_fn.value = s;
} else if (s is DataItem){
_fn=s;
} else {
trace('invalid type at firstname');
}
}
public function get lastName():*{
return _ln;
}
public function set lastName(s:*):void{
if (s is String){
_ln.value = s;
} else if (s is DataItem){
_ln=s;
} else {
trace('invalid type at lastname');
}
}
public function get country():*{
return _country;
}
public function set country(s:*):void{
if (s is String){
_country.value = s;
} else if (s is DataItem){
_country=s;
} else {
trace('invalid type at country');
}
}
public function get eMail():*{
return _eMail;
}
public function set eMail(s:*):void{
if (s is String){
_eMail.value = s;
} else if (s is DataItem){
_eMail=s;
} else {
trace('invalid type at eMail');
}
}
public function get phone():*{
return _phone;
}
public function set phone(s:*):void{
if (s is String){
_phone.value = s;
} else if (s is DataItem){
_phone=s;
} else {
trace('invalid type at phone');
}
}
public function get aff():*{
return _aff;
}
public function set aff(s:*):void{
if (s is String){
_aff.value = s;
} else if (s is DataItem){
_aff=s;
} else {
trace('invalid type at affiliation');
}
}
public function get more():*{
return _more;
}
public function set more(s:*):void{
if (s is String){
_more.value = s;
} else if (s is DataItem){
_more=s;
} else {
trace('invalid type at more');
}
}
public function allValid():Boolean{
//assume valid
_allValid = true;
//check each property for valid
if (!_fn.isValid){_allValid=false}
if (!_ln.isValid){_allValid=false}
if (!_country.isValid){_allValid=false}
if (!_eMail.isValid){_allValid=false}
if (!_phone.isValid){_allValid=false}
return _allValid;
}
}
}
package com.magnoliamultimedia.vo
{
[Inspectable]
[DefaultProperty('value')]
public class DataItem extends Object
{
private var _value:String;
private var _minLength:int;
private var _maxLength:int;
private var _isRequired:Boolean;
private var _vType:String;
private var _isValid:Boolean;
public function DataItem(v:String, mn:int=-1,
mx:int=-1, rq:Boolean=false, vt:String='StringValidator'){
this.value=v;
this.minLength=mn;
this.maxLength=mx;
this.isRequired=rq;
this.validatorType=vt;
_isValid=!rq;
}
public function toString():String{
return _value;
}
public function get value():String{
return _value;
}
public function set value(v:String):void{
_value = v;
//if string length goes to 0 and this
is
//not a required property, it is
automatically
//valid
if (v.length==0){
_isValid=!_isRequired;
}
}
public function get minLength():int{
return _minLength;
}
public function set minLength(m:int):void{
_minLength = m;
}
public function get maxLength():int{
return _maxLength;
}
public function set maxLength(m:int):void{
_maxLength = m;
}
public function get isRequired():Boolean{
return _isRequired;
}
public function set isRequired(r:Boolean):void{
_isRequired = r;
}
public function get validatorType():String{
return _vType;
}
public function set validatorType(v:String):void
{
_vType = v;
}
public function get isValid():Boolean{
return _isValid;
}
public function set isValid(b:Boolean):void{
_isValid = b;
}
}
}
I have a function that then automatically validates these controls with
validators I've set up in MXML:
private function dataItemFocusOut(di:DataItem, e:Event):void{
var result:ValidationResultEvent;
if (di.validatorType=='StringValidator'){
var sV:StringValidator=sValidator;
sV.minLength=di.minLength;
sV.maxLength=di.maxLength;
sV.listener=e.currentTarget;
sV.required=di.isRequired;
result = sV.validate
(e.currentTarget.text);
} else if (di.validatorType=='EMailValidator'){
var eV:EmailValidator=eValidator;
eV.listener = e.currentTarget;
eV.required = di.isRequired;
result = eV.validate
(e.currentTarget.text);
} else {
trace('this code doesn\'t provide a
validator of type "'+di.validatorType+'".');
var dontValidate:Boolean=true;
}
if (result.type==ValidationResultEvent.VALID){
di.isValid=true;
} else if (!dontValidate) {
di.isValid=false;
}
if (nav.selectedIndex==0){
validateContactDetails();
}
}
and my validateContactDetails function looks like this:
private function validateContactDetails():void {
if (contactDetails.allValid()){
//enable next tab in TabNavigator
trace('all valid');
presentationForm.enabled=true;
} else {
trace('not all valid');
}
}
If these do work for you, please let me know, because I spent hours
getting to this point. It would be nice to know those hours went to
help someone else. Somehow it would seem more worth ti :-).
HTH;
Amy