Problems with closeField

JonathanC at JonathanC at
Tue Sep 14 07:39:48 EDT 2004

Dear Wilhelm,

Thank you very much for replying (and especially for making sure I SAW 
your reply, since the Digest mixed up my post).

I, too, had since worked out an exitField version. However, yours is more 
elegant than mine: e.g. using a 'script local variable' rather than a 
global variable. :-)

What I still don't understand (and perhaps you don't either, given your 
comment "This is contrary to what you would expect from the docs") is why 
the field doesn't send a closeField when the contents of the field have 

Here's the problem, again, in its simplest form:

Create a field with the following script:

on openField
  put empty 
end openField

on keydown k
  if charToNum(k) is among the words of "3 8 9 13 28 29 30 31" 
    then pass keyDown
  put k into selection
end keydown

on closefield 
  put "Field changed."
end closefield

Typing into the field produces completely normal behaviour: arrowkeys, the 
deletekey and backspace key are passed, and everything else is handled by 
the line "put k into selection". But when you click out of the field, NO 
closeField message is sent.

Now delete (or comment out) the keyDown handler. Type into the field and 
click out of it: The message box reports (correctly) that the field has 

Since HyperCard sends closeField in both situations, I gather that 
Revolution must have its own definition of 'closeField'.
Can anyone from RunRev (or with inside knowledge) confirm this?


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

use-revolution-bounces at wrote on 13/09/2004 02:55:37 AM:

> Because the original post got mixed up with the post of Nicholas 
> Thieberger <thien at> (Subject: Re: use-revolution Digest, 
> Vol 12, Issue 45) in the digest version and was therefore not noticable 
> for Jonathan Cooper by subject, I re-post my message from this morning 
> and add the new script.
> On Tue, 7 Sep 2004, JonathanC at wrote:
> > I can't believe I'm having a problem with something as simple as
> > "closeField"!
> >
> > I have a field which works like the Address bar of Internet Explorer. 
> > When
> > you start typing into it, it tries to finish the word or phrase, 
> > according
> > to a list in a separate field (which will eventually be hidden). If 
> > end up typing a NEW word or phrase, you are asked if you would like 
> > added to the list, for next time. I got it to work fine in HyperCard, 
> > I'm stumped by the strange behaviour of "closeField".
> Hi Jonathan,
> Finally I managed to take a look at your sample stack; sorry for the 
> After some experimenting I changed three things in the script of fld 
> "auto-complete":
> - 1. I changed the "closefield" handler to a "exitfield"
> This is contrary to what you would expect from the docs
> (closefield = the field's content has changed
> exitfield = the contents of the field have not changed),
> but it seems to work.
> - 2. I intercepted the "Cancel" message of the modal dialog which now 
> sets a variable ("ControlVar") to false - to avoid the modal dialog to 
> be repeated again and again
> - 3. I declared a local var in the first line of the field script and 
> set "ControlVar" to true at the beginning of the "keydown" handler
> This seems to solve your  immediate problems as you stated them. There 
> are probably a number possibilities to refine and enhance your 
> auto-complete routines.
> Best regards,
> Wilhelm Sanke
> <>
> ============================
> P.S.:
> New script of field "auto-complete" of your stack "CloseField problem":
> local ControlVar
> on keydown k
>   put true into ControlVar
>   global autoCompleteList
>   if autoCompleteList = "" then pass keyDown
>   if " " & charToNum(k) & " " is in " 3 8 9 13 28 29 30 31 " then pass 
> keyDown
>   put k into selection
>   put me into what
>   if what="" then pass keydown
>   get offset(return & what,return & autoCompleteList)
>   if it>0 then
>     put the number of lines in (char 1 to it of autoCompleteList) into 
> thisline
>     put line thisline of autoCompleteList into me
>     select char length(what)+1 to length(me) of me
>   end if
> end keydown
> on openField
>   put empty into fld "Message"
>   -- pass openField
> end openField
> on exitfield
>   put "Field changed." into fld "Message"
>   global autoCompleteList
>   put me into temp
>   if controlVar is true then
>   if temp <> "" and not (temp is among the lines of autoCompleteList) 
>     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 if it is "Cancel" then
>       put false into controlVar
>       end if
>   end if
>   end if
>   pass exitfield
> end exitfield
> _______________________________________________
> use-revolution mailing list
> use-revolution at

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