DataGrid Cell validation - comments please

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

DataGrid Cell validation - comments please

Post by Simon Knight » Sat May 28, 2011 8:15 am

Hi,
I have a datagrid that uses database "key" values as column names. The database holds details about the legal range of values that may be set in any column. So when the user enters a value in the datagrid I wish to have the entry validated against the range described in the database. The external (to the datagrid) validation routine requires the field key which the datagrid stores as a column name and the value the user has entered. The value being checked is returned if it is within the legal range otherwise a default value is returned.

I have written the following script which is placed in the datagrid group. While the script works I have a feeling that there might be a better/ more elegant way of calling the validation routine.

My script, comments please:

Code: Select all

On CloseFieldEditor pFieldEditor
   
   //calls a validation routine on the Encode decode stack
  
  // Extract the information needed to do the validation check
   put the dgColumn of the target into tColumn -- tColumn is used as a search key in a data table
   put the text of PFieldEditor into tValue  -- Text the user entered in the cell
   
   // Validate the entry
   put ValidateEntry(tColumn,tValue) into tValidData  -- returns with a valid value either the user entry or a default value
   // Write data to the datagrid cell
   set the text of pFieldEditor to tValidData  -- write the text back to the cell
end CloseFieldEditor
best wishes
Skids

Post Reply