Problems with closeField

JonathanC at JonathanC at
Wed Sep 8 09:47:14 EDT 2004

In response to my message of 07/09/2004 07:41:17 PM, which went, in part:

> The "Auto-complete" field contains a closeField handler, which checks 
> contents against another field ("Auto-complete list") and offers to add 
> new line, if required.
> However, the closeField handler seems to only be triggered when the 
> Expected behaviour (i.e. closeField triggered when new text is entered 
> or the field is emptied) returns when the keydown handler is removed 
> the script of field "auto-complete" (or commented out).
> Then a NEW problem occurs: If you enter a word/phrase that doesn't 
> in the "Auto-complete list" field and then click out of the field, an 
> answer dialog appears:
>     Add <new text> to auto-complete list?
> If you click "Cancel", the focus returns to the "Auto-complete" field. 
> Then, if you click out of the field again, the whole thing starts again! 

> And so on, until you click "OK". 
> This is weird: Why does closeField not get triggered when (I think) it 
> should, but then get triggered when (I think) it shouldn't?
> Passing or not passing "closeField" makes no difference.

... Sarah Reichelt wrote on 08/09/2004 08:25:19 AM:

> It sounds like the field doesn't think it has changed unless you pass 
> the key messages. Perhaps you could trap openField and record the 
> original contents of the field, then on exitField or focusOut, check if 
> it has changed and offer to save that way.

Ken Ray also suggested the problem might be because I don't (normally) 
pass keyDown. Trouble is: if I add a "pass keydown" at the end, 
Eevveerryytthhiinngg  ccoommeess  oouutt  ddoouubbllee :-) (not 
surprisingly, since the script already takes care of putting or removing 
any typed characters).

Yes, I have thought of bypassing closeField altogether (1. record original 
contents of field in a global. 2. on EXITfield, compare with new contents) 
and I "sort of" got it to work (see below*), but I would like to know - 
what is it about Revolution that makes the behaviour of closeField so 
different to HyperCard?

* Here's where the 'exitField workaround' almost came unstuck for me:
If I entered a new word or phrase and then exited the field, the dialog 
"Add <new text> to auto-complete list?" popped up. If I clicked "Cancel", 
the insertion point got placed back in the field, just as if I had never 
left. I know this because, if I then clicked out of the field, the dialog 
would pop up again (so obviously the global was still its original value).
Time for _another_ workaround (!): This time, I had to add a line to 
change the global variable to the new text and then "select empty".
So, my openField & closeField handlers were now like this (new lines 
marked with "-- <<"):

on openField
  global gOrigFldContent -- <<
  put me into gOrigFldContent -- <<
  put empty into fld "Message" -- (test line only)
  pass openField
end openField

on exitField
  global autoCompleteList
  global gOrigFldContent -- <<
  if me = gOrigFldContent then pass exitField -- <<
  put "Field changed." into fld "Message" -- (test line only)
  put me into temp
  if temp <> "" and not (temp is among the lines of autoCompleteList) then
    answer "Add" && quote & temp & quote && "to auto-complete list?" \
        with "Cancel" or "OK"
    if it = "OK" then
      if last char of autoCompleteList <> return and the length of \
         autoCompleteList > 0 then put return before temp
      put temp after autoCompleteList
      put autoCompleteList into fld "Auto-complete list"
    else put me into gOrigFldContent -- <<
    select empty -- <<
  end if
  pass exitField
end exitField


P.S. Sorry to anyone who tried to download my little stack (as 
"") but failed. There were problems with our domain 
name, which have been sorted now.
I have uploaded a NEW stack that has both the old, closeField, version and 
the new, exitField, version:

Jonathan Cooper
Manager of Information / Website
Art Gallery of New South Wales
Sydney, Australia

This e-mail message is intended only for the addressee(s) and contains 
information which may be confidential.  If you are not the intended 
recipient please advise the sender by return email, do not use or disclose 
the contents, and delete the message and any attachments from your system. 
 Unless specifically indicated, this email does not constitute formal 
advice or commitment by the sender or the Art Gallery of NSW  (ABN 24 934 
492 575) or its related entities.

More information about the use-livecode mailing list