Title: Custom dg validator

Gary,

I put your code into a sample application.  For me, it returned a validation error for any value that is put into the TextInput object.  I modified your code to get validation working, although it is still ignoring the colName variable.  I am not sure where that value is being set or what it represents.  How is this being used?  Are you using it as a custom implementation for a normal mx:TextInput object, or are you using it as a custom cell renderer for a mx:DataGrid object?

 

<?xml version="1.0" encoding="utf-8"?>

<mx:TextInput xmlns:mx="http://www.macromedia.com/2003/mxml" >

            <mx:Script>

            <![CDATA[

 

                                    function customValidate() {

 

                                                var validator = arguments[0][0].validator;

 

if ( this.text != "test" )   validator.validationError( null, "The value does not equal 'test'.", null );

                                    }

            ]]>

            </mx:Script>

 

            <mx:Model id="theModel">

              <text>{text}</text>

            </mx:Model>

 

            <mx:Validator field="theModel.text" validate="customValidate(arguments)" listener="this" />

 

</mx:TextInput>

 

-Andy

 

 

_____________________________________

Andrew Trice

Cynergy Systems, Inc.

http://www.cynergysystems.com

 

Email: [EMAIL PROTECTED]

Office: 866-CYNERGY 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Ault, Gary - BLS
Sent: Wednesday, April 12, 2006 2:30 PM
To: [email protected]
Subject: [flexcoders] Custom dg validator

 

In Flex 1.5, I am trying to create a PowerBuilder-esque column validator. I use a custom TextInput field with a Validator so that when a user tabs out of a column, the validation check is triggered. It appears to work for a simple test, but I cannot get the validation error to trigger for other conditions. Can anyone see a flaw or have another approach to share? Thanks.  Here is my custom TextInput with validator:

<?xml version="1.0" encoding="utf-8"?>
<mx:TextInput xmlns:mx="http://www.macromedia.com/2003/mxml" >
<mx:Model id="theModel">
  <text>{text}</text>
</mx:Model>

<mx:Validator field="theModel.text" validate="customValidate( event )" listener="this" />

<mx:Script>
<![CDATA[
                               
       
function customValidate(event ) {
               
var validator = event.validator;
               
var value = event.value;
               
var colName = event.colName;
               
//this works
               
//if ( value != "test" )
                       
//validator.validationError( null, "Value must be an arithmetic operator", null );
               
//this does not work
               
if (colName =="rptPricesOper" && value != "test")
                               
validator.validationError( null, "Value must be an arithmetic operator", null );
                               
       
}  // end customValidate
       
]]>
</mx:Script>

</mx:TextInput>

 

Gary Ault
Bureau of Labor Statistics




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to