OK, this wasn’t trivial to figure out because I had issues getting it to work with binding involved.  SoI took out the binding.  You’ll also see what I did to avoid some of the resetting due to mouse movement.  It may not be perfect, I didn’t test every scenario, but this should get you farther.

 

<?xml version="1.0"?>

<mx:TextInput xmlns:mx="http://www.macromedia.com/2003/mxml" change="needCommit=true" valueCommitted="doUpdate()">

    <mx:Script>

        <![CDATA[

      import mx.validators.Validator;

      import mx.controls.DataGrid;

      privatevar listOwner:DataGrid;

      privatevar getCellIndex : Function;

      privatevar getDataLabel : Function;

      privatevar settingValue : Boolean = true;

      privatevar needCommit : Boolean = false;

      privatevar item : Object;

      privatevar itemIndex : Number;

     

 

      function doUpdate() {

          if (settingValue) return;

          listOwner.editField(itemIndex, getDataLabel(), text);

          if (Validator.isValid(this, "text")) {

              item.valid=true;

           } else {

              item.valid=false;

           }

           needCommit = false;

       }

 

      function setValue( str:String, item:Object, sel:Boolean ) {

          if (needCommit && itemIndex == getCellIndex().itemIndex) return;

          itemIndex = getCellIndex().itemIndex;

          settingValue = true;

          this.item = item;

           if (item==undefined) {

             this.clear();

           } else {

             this.text = str;

           }

          settingValue = false;

      }

      ]]>

    </mx:Script>

 

    <mx:PhoneNumberValidator field="text" listener="this"/>

</mx:TextInput>

 

Matt

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 08, 2005 11:28 AM
To: [EMAIL PROTECTED]
Subject: Re: [flexcoders] Validating datagrids

 

Hi Matt,

 

thank you for your reply...

I have tried out your suggestion thoroughly:

 

-I have solved the problem I had with the validation of all Datagrid-entries. Actually I add a valid-attribute to each validated object, which either has the value false or true.

At the end I go through all my datagrid-entries and onlydo the database-update if all entries are either valid=true oder valid=undefined.

-However, I could not solve the problem I have with going back to the initial value.Flex always calls the setValue-function of the cellRenderer whenever I scroll with my mouse over the datagrid-entries.If I alter a datagrid-entry, most times it goes back to the initial value (but NOT always).How come? Do you have another idea perhaps?

 

Reply via email to