1 Reply Latest reply on Apr 26, 2007 10:09 AM by BiSaisei

    Validation of user inputs when using ItemRenderers in DataGrid


      I have to show multiple editable columns in a DataGrid.
      The columns may have different formats and datatypes e.g. numbers, dates, string etc.
      So I am using TextInput/DateField as a ItemRenderer inside the DataGrid. I have also set the rendererIsEditor="true".

      Now I want to apply validation to all these editable columns depending on their datatypes.
      I know I can do that by applying validators individually on each column.

      But is there a way I can use common validation for all the columns that have a similar datatype or that have the same renderer?
        • 1. Re: Validation of user inputs when using ItemRenderers in DataGrid
          You can use the itemEditEnd Event of the DataGrid for your validation. Then you can use Actionscript to make sure what the user enters is in the right format. Example:

          import mx.events.DataGridEvent;

          public function processEdit(event:DataGridEvent):void {
          cellValue = TextInput(event.currentTarget.itemEditorInstance).text; // the entered text
          cell = event.dataField; //the datafield attribute of the column

          // Determine if the new value is too long for nvarchar field
          if(cell == 'WLNET' && cellValue.length > 35) {
          cellValue = cellValue.substr(0,35); //shortening it for user demonstrates expected length
          TextInput(event.currentTarget.itemEditorInstance).text = cellValue;
          event.preventDefault(); // Prevent the user from removing focus, and leave the cell editor open.

          // Write a message to the errorString property.
          // This message appears when the user mouses over the editor.
          TextInput(event.currentTarget.itemEditorInstance).errorString="Entered text too long.";

          <mx:DataGrid id="enrolled_dg" editable="true" itemEditEnd="processEdit(event);">

          I learned part of this from the Flex documentation online: Determining the reason for an itemEditEnd event