Page 1 of 1
Interrupting a go next or go prev
Posted: Mon Nov 09, 2009 12:04 pm
by exheusden
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?
Posted: Mon Nov 09, 2009 12:54 pm
by Mark
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
Posted: Mon Nov 09, 2009 1:54 pm
by exheusden
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.
Posted: Mon Nov 09, 2009 3:02 pm
by Mark
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
Posted: Mon Nov 09, 2009 5:46 pm
by sturgis
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.
Posted: Mon Nov 09, 2009 6:21 pm
by Mark
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
Posted: Mon Nov 09, 2009 11:51 pm
by exheusden
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.