3

Once a record has been saved to the database, I want to have any field change color to indicate that the user has made uncommitted changes if they type into that field.

Is it best to just set the foreColor on closeField, or is it better to track each keypress, and compare it against a variable containing the previous field content?

Roger Eller
  • 113
  • 1
  • 6

3 Answers3

4

Are you asking how to detect a text change once a process that loaded field data has been made, and new, unsaved data is being entered? You mentioned new uncommitted changes, and I am not sure what you have in mind. This means that using a closeField handler will not indicate "uncommitted changes if they type into that field"

If so, however, I would set a custom property of the field upon writing to the database, and put a simple handler in the field script

on textChanged
   if me <> the lastText of me then set the foreColor of me to "blue"
end textChanged

The property is named "the lastText", and is set by whatever handler saves to the database.

set the lastText of field "yourField" to field "yourField"

The color will change to blue if anything is edited within that field. Of course, the saving handler ought as well to set the color back to black.

dunbarx
  • 146
  • 2
  • Yes, a search, or new record button would reset the foreColor to empty or black. I also considered a generic catch all when the card or stack closes. answer warning "Data has been altered. If you exit, changes will be lost." But I think real time colorization is more effective. – Roger Eller Mar 11 '13 at 03:24
1

Here's a card level script to handle all the fields on a form. When you load the data on to the card, set each field's uOriginalText custom property to the same value as the text loaded into the field.

on closeField
   # the target control for this message
   put the target into tTarget

   # detect case changes like 'mr jobs' to 'Mr Jobs'
   set the caseSensitive to true

   # compare with the original text, set when the form was loaded
   if the text of tTarget <> the uOriginalText of tTarget then
      # indicate the change - I've used backColor in case the field is now empty
      set the backColor of tTarget to "red"
   else
      # clear warning background color
      set the backColor of tTarget to empty
   end if
end closeField
splash21
  • 799
  • 4
  • 10
  • I use a tabbed button to hide/show groups on a card. Not all groups are part of the "form". Could I restrict this behavior to a single group by changing line 3 to `put the target of grp "myForm" into tTarget`? – Roger Eller Mar 12 '13 at 01:02
  • You could set another custom property of each field that IS part of the form, example - uFormField. You could then add the following after line 3 : if the uFormField of tTarget then ..... – splash21 Mar 12 '13 at 14:35
1

In glx2 we actually do a bit of overkill - save the md5digest of the field when you save it, then check the md5digest of the field against the saved value to see if it needs saving. Obviously you don't want to do the computation on each keypress, no matter how fast it is. Doing that on closeField is a good way to deal with it, although I seem to remember having a problem in the past with closeField not getting triggered if you click onto another app on OSX.

mwieder
  • 231
  • 2
  • 6