Field listener

Sarah Reichelt sarah.reichelt at gmail.com
Sun Sep 10 16:41:03 EDT 2006


On 9/11/06, Trevor Hopkins <tjhopkins224 at hotmail.com> wrote:
> I'm trying to build a form whose "submit" button only becomes enabled after
> text is present in a specific field (and likewise when that field is blank,
> the "submit" button returns to disabled status). Does anyone know of a
> painless way to do this? I'd also like the user to be able to hit return
> from within that field and have the "submit" button entered. Right now, it
> seems, the return key must be hit twice in order to first exit the field and
> then select "submit".


I like to use a "send in time" message that checks all the relevant
fields and enables or disables buttons accordingly. I prefer it to
closeField as it happens in real time, instead of waiting for the user
to get out of the field.

For example:

-- start the messsage going
on openCard
  send "checkButtons" to me
end openCard

-- check all the things you need & set the button
-- you can make this check as complex as you like
on checkButtons
  if fld "Essential" is empty or fld "Number" is not a number then
    disable btn "Submit"
  else
    enable btn "Submit"
  end if

  -- send the message again
  if the pendingMessages contains "checkButtons" is false then
    send "checkButtons" to me in 10 ticks
  end if
end checkButtons

-- stop the message when closing the card
on closeCard
  put the pendingMessages into tList
  repeat for each line L in tList
    if item 3 of L contains "checkButtons" then cancel item 1 of L
  end repeat
end closeCard


Then for the Return key being able to hit the button:

on returnInField
  click at the loc of btn "Submit"
end returnInField

I like this method as it won't do anything if the button is disabled,
and if it does work, it gives visual feedback of the buttoon being
clicked.

Don't forget that you can also use enterInField and if the autoTab is
set to true, you might like to use the tabKey message.

HTH,
Sarah



More information about the use-livecode mailing list