Interrupting a go next or go prev

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Interrupting a go next or go prev

Post by exheusden » Mon Nov 09, 2009 12:04 pm

I want to verify the contents of a field.

Code: Select all

on closeField
   if there is not a card name ("House" && target) then
      answer "Error:" && target && "is invalid" with "Okay"
      select text of the target
   end if
end closeField
The code works, except that, when the field is left through a go next or go prev button (provoking the closeField message), the error is shown correctly, but the next or prev card is shown when the Okay button is pressed. Somehow, I need to interrupt the go next or go prev, so as to stay on the error card.

But how?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Nov 09, 2009 12:54 pm

Dear exheusden,

The easiest way is to do this in your button.

Code: Select all

on mouseUp
  put validate() into myAllOK
  if myAllOK then
    -- go somewhere
  else
    beep
    answer error myAllOK
  end if
end mouseUp

function validate
  if there is a card ("House" && the text of the target) then
    return true
  else
    return "Error:" && target && "is invalid"
  end if
end validate
You can adjust the validate function to include checks for many fields and create an error message depending on which fields are invalid.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Post by exheusden » Mon Nov 09, 2009 1:54 pm

I see what you're getting at, Mark, but I don't think this works as it stands, given the use of "the target"; this will point to the button, surely, and not to the field contents.

The idea of a function is good, but the error-checking script will need to be expanded. I'll see what I can do.

Thanks for the input.

Edit: there is a caveat, too: the script must apply to several similar fields. At the moment, using on closeField applied to a group of fields works -- as long as the go next and go prev don't come into play.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Nov 09, 2009 3:02 pm

Dear exheusden,

Of course, you are completely right. The "target" should be replaced with a reference to a field.

You might write a validate script that either checks a list of given fields or all fields on your card if no list is provided.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Mon Nov 09, 2009 5:46 pm

Isn't this a question of precedence? on closeField should fire before the buttons mouseUp I believe which means you can set an error flag in closeField and check it in your buttons mouseUp handler.

edit: This gets more confusing if you're building for both windows and mac since closeField won't trigger off of a button click on a mac, but shouldn't be too difficult to get around.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Nov 09, 2009 6:21 pm

Dear Sturgis,

I see you've noticed the problems already. That's why it is better to validate the fields independently of wheher the closeField message is triggered.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Post by exheusden » Mon Nov 09, 2009 11:51 pm

sturgis wrote:This gets more confusing if you're building for both windows and mac since closeField won't trigger off of a button click on a mac, but shouldn't be too difficult to get around.
It seems to me that the closeField is triggered by a button-click, for that is exactly how I noticed the problem: a go next button first caused the closeField script to run, which was immediately followed by the mouseUp (go next) script.

I've had to use the option of an error flag, set at closeField and checked before the go next.

Post Reply