Empty Field Validation puzzle or wt*

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Empty Field Validation puzzle or wt*

Post by Lagi Pittas » Wed May 03, 2017 10:44 am

Hi

There are many ways to skin a cat so the other day I thought I would tidy up some code and put it in a behavior to validate a group of 4 fields.
Since ALL the field were required I added code to make sure they couldn't move to the next field if it was blank.

this is the most basic version below:-

Livecode Version 6.7 and livecode 9 dp6 (to see if it was a consistent bug/undocumented feature)

Code: Select all

on KeyDown pKey
   put pKey  into the selectedtext
end KeyDown

on EnterInField
   ReturnInField
end EnterInField
 
 on ReturnInField
     type tab
 end ReturnInField
   
on CloseField 
   put me && the target
   if  me is empty  then  
      focus on the target
   end if
end CloseField

on ExitField
   put me && the target
   if me  is empty   then  
      focus on the target
   end if
end ExitField
I trap the enter and return keys (for some reason my Logitech Keyboard is marked "enter" but returns "return")
I also make enter/return type a TAB character so if they hit return/enter or TAB rather instead of tapping on the next field) it will still go to the next field.

Anyway it didn't work.

Ok it could be because its in a behavior - so I put it in to a group consisting of the 4 fields.

That didn't work either.

Ok try field level - still didn't work.
Try version 9 of livecode - Nope
Curiouser and Curiouser cried Alice
if I put a breakpoint where i test for empty and single step it works as it should.

This sounds like I spent 2 minutes testing this but I wasted hours trying to see if there was a way to get this little bit of code (the essence of of the routine) working as it should. - or as usual am i missing something.

There are many ways to solve this - and i've used more than 1 previously but this SHOULD work.

Regards Lagi

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Empty Field Validation puzzle or wt*

Post by dunbarx » Wed May 03, 2017 3:55 pm

Why not just this, in the card script:

Code: Select all

on enterInField
   if target <> "" then type tab
end enterInField

on returnInField
   if target <> "" then type tab
end returnInField

on tabKey
   if target <> "" then pass tabKey
end tabKey
I don't think you need any of the other handlers.

Craig Newman

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: Empty Field Validation puzzle or wt*

Post by Lagi Pittas » Wed May 03, 2017 4:24 pm

Hi Craig,

This is part of a generic validation routine for dates, currencies making uppercase (hence the rawkeydown) and other tests.

As I said there are other ways i have done it but on each new program I try to rewrite my validation routines in a new a new way to solve and ultimately aggregate them to use what I would think is the better way - we are always learning - more so with LC. It's like Perl 10 ways to do the same thing but actually readable afterwards.

My reason for posting is not that I can't do it another way , it's that this farty bit of code doesn't work as it should, but even more baffling is that if it is single stepped it does work.

Is it a bug, is it the way the message hierarchy works, is it a plane, is it ....? no its Livecode

Lagi

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Empty Field Validation puzzle or wt*

Post by dunbarx » Wed May 03, 2017 6:07 pm

I have had single stepped routines work where simply running the handler does not. This goes way back to HC days. Most often, once I do make it work single stepped, the usual running of the script seems to fix itself.

No idea why. Mild mannered LC will not say.

Craig

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Empty Field Validation puzzle or wt*

Post by MaxV » Thu May 04, 2017 1:43 am

Code: Select all

on exitField -- remove visual signs that the field is being edited
set the showBorder of the target to false
focus on me
end exitField
That's all folks! :D

Read the differences between: http://livecode.wikia.com/wiki/ExitField and http://livecode.wikia.com/wiki/CloseField
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Empty Field Validation puzzle or wt*

Post by SparkOut » Thu May 04, 2017 6:39 am

Is the field set with autoTab true?
That would avoid the need to send a tab from the enterInField and returnInField handlers

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: Empty Field Validation puzzle or wt*

Post by Lagi Pittas » Thu May 04, 2017 5:51 pm

HI

I had the TabonReturn set but if you have a keydown then you have to take over the TAB somehow - and it's cleaner to do it with the enterinfield as there is no checking of ascii codes etc.


I Tested it on Mac and Windows (probably thats why at one stage it seemed to work).

But when I read the links that Max gave I can (maybe?) see why it worked in debug mode - because we are focusing other windows and then coming back.

Any I spent another hour or so messing and using Max's focus border - CLose but no Cigar.

If you use the keyboard it works but cant for teh life of me get it so that the hihlites work in sync, plus when you use the mouse (or finger) all bets are off - so we need another Kludge for that.

Ill do it the long winded and NON generic way way but it should be so simple

Thanks Guys

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”