1 Reply Latest reply on Nov 29, 2007 4:34 AM by atta707

    validator for datagirdcolumn

    alain nkomo
      hi i have a little proble with my application and i need some help i'll like to valide a field of a data gridcolunm and i dont know how to do for example

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script >
      import mx.collections.ArrayCollection;
      private var Anagrafica:ArrayCollection = new ArrayCollection;
      <mx:DataGrid id = "mydatagrid"x="222" y="156" dataProvider="{Anagrafica}">
      <mx:DataGridColumn headerText="Nome" dataField="nome" editable="true"/>
      <mx:DataGridColumn headerText="Email" dataField="mail" editable="true"/>
      <mx:DataGridColumn headerText="Telefono" dataField="tel" editable="true"/ >
      <mx:StringValidator id="stingval" source="{}" />
      <mx:PhoneNumberValidator id="phoneval" source="{}"/>
      <mx:EmailValidator id="emailval" source="{}"/>


      i want to validate the value of the field email of mydatagrig with the emailvalidator it is possible ? i tried to put an id to the filed
      <mx:DataGridColumn headerText="Nome" dataField="nome" editable="true" id ="test"/ > and give it to "source"
      <mx:EmailValidator id="emailval" source="{test}"/> but it doesnt work hellpppppp
      sorry for my english
        • 1. Re: validator for datagirdcolumn
          atta707 Level 2
          Your English is fantastic! Don't worry about it!

          Now, onto the solution! Here is *one* way you can do it:

          register an event handler for itemEditEnd event

          public function itemEditEndHandler(event:DataGridEvent) : void {
          var newData:String = TextInput(event.currentTarget.itemEditorInstance).text;

          if (!Number(newData)) {
          TextInput(this.blocksDataGrid.itemEditorInstance).errorString = "Please enter a valid number between 0 and 100.";

          so essentially you validate data either thru a validator or just by plain IF statemetments, and if it fails you preventDefault on the event and assign an error message to the editor.

          Another way of doing it would be to write you editor.

          Yet another way of doing it would be to do it itemFocusOut event.

          Hope this get you started.