Problems with closeField

Wilhelm Sanke sanke at hrz.uni-kassel.de
Sun Sep 12 12:55:37 EDT 2004


Because the original post got mixed up with the post of Nicholas 
Thieberger <thien at unimelb.edu.au> (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 ag.nsw.gov.au 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 you
> end up typing a NEW word or phrase, you are asked if you would like this
> added to the list, for next time. I got it to work fine in HyperCard, but
> 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 delay.

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
<http://www.sanke.org>

============================

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) 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 if it is "Cancel" then
      put false into controlVar
      end if
  end if
  end if
  pass exitfield
end exitfield




More information about the use-livecode mailing list