How to tell if a field is "closed"?

Mark Waddingham mark at livecode.com
Tue Feb 5 14:53:41 EST 2019


On 2019-02-05 20:25, Paul Dupuis via use-livecode wrote:
> I have a problem for which I should probably redesign the user
> interface, but would rather not do so for many reasons.
> 
> The problem is this:
> 
> 1) There are some fields on a card. Each field has a "closeField"
> handler that checks the fields content for validity and presents
> appropriate error messages (via a standard 'answer" command).
> 2) There is an "Import" button that collects the field values and lots
> of other data and does a task in my application.
> 3) If a user edits a fields and enters an invalid value and does not
> click, tab, or press the return key to "close" the field and trigger
> the "closeField" message, but immediately clicks on the "import"
> button, my import script starts using the invalid value from the open
> field while at the same time a closeField message does get send and an
> answer dialog appears telling what is invalid about the entry.
> 
> However, I am wondering if anyone in the LiveCode brain trust has
> figured out a better way to handle something like this?

How about this...

In your closeField handlers, if the field fails validation do:

   if <not validated> then
     answer "Field failed validation" with "Oops - I'll correct it" or 
"Cancel"
     if it is "Cancel" then
       exit to top
     end if
     focus on me
     exit closeField
   end if

Then in your import button do:

   on mouseUp
     focus on nothing
     if the selectedField is not empty then
       exit mouseUp
     end if
     answer "Go!"
   end mouseUp

This should mean the import step won't run until a closeField handler 
has successfully finished.

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps




More information about the Use-livecode mailing list