Advancing from field to field

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
DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Advancing from field to field

Post by DavJans » Fri Jul 07, 2017 6:07 pm

When filling out fields with "Tab on Return" turned on as you hit Enter or Tab for that matter the cursor advances to the next field. Great :)

I am trying to manipulate this to work a little bit different like so,

Code: Select all

on closeField
   if fld "field2" is empty then
      focus on fld "field2"
   else
      if fld "field3" is empty then
         focus on fld "field3"
      else 
         if fld "field4" is empty then
            focus on fld "field4"
         else
            focus on fld "field5"
         end if
      end if
   end if
end closeField
This works great! in livecode, however when it is saved as a windows stand alone application it does not work.
Does anyone have any other Ideas for me that wight work.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

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

Re: Advancing from field to field

Post by MaxV » Mon Jul 10, 2017 12:02 pm

I'd change your code to this, and put it in the card:

Code: Select all

on exitField 
 answer "Hey, the field is empty/unchanged!"
end exitField
See: http://livecode.wikia.com/wiki/ExitField
Best regards
Max
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7254
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Advancing from field to field

Post by jacque » Mon Jul 10, 2017 4:43 pm

What happens when it doesn't work? Does any field get selected or is the command ignored entirely?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Advancing from field to field

Post by DavJans » Tue Jul 11, 2017 11:09 pm

In a standalone windows environment the script is ignored most of the time and it just advances to the next field like the script wasnt there at all. from field1 to field2 and from field2 to field3 and so on.

This code works better, but not what I want because it makes it harder to change the value in a field.

Code: Select all

on openField
      if fld "field3" is empty then
      else
         focus on fld "field4"
      end if
end openField
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7254
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Advancing from field to field

Post by jacque » Wed Jul 12, 2017 8:11 pm

This should do what you want:

Code: Select all

local sFlds = "fld1,fld2,fld3,fld4,fld5" -- use the real field names here

on tabKey
  if "field" is not in the name of the target then exit tabKey
  if target = "" then pass tabKey
  selectNextEmptyFld
end tabKey

on selectNextEmptyFld
  put the short name of the target into tCurFld
  put itemOffset(tCurFld,sFlds) into tStart
  repeat with x = tStart to the number of items in sFlds
    put item x of sFlds into tFldName
    if fld tFldName = empty then
      select text of fld tFldName
      exit repeat
    end if
  end repeat
end selectNextEmptyFld
Note that this is one case where using "the" matters. "The target" and "target" are different things.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7254
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Advancing from field to field

Post by jacque » Wed Jul 12, 2017 8:24 pm

Actually, the above script may not be exactly what you want. What do you want it to do if the selected field is already empty? Right now it uses the normal tab behavior. Also, it doesn't wrap around, but your example didn't do that either.

If you want the selection to stay in an empty field without moving, remove the second line of the tabKey handler.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7254
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Advancing from field to field

Post by jacque » Wed Jul 12, 2017 8:32 pm

This one wraps around and doesn't use normal auto-tab behavior:

Code: Select all

local sFlds = "fld1,fld2,fld3,fld4,fld5" -- use the real field names here

on tabKey
  if "field" is not in the name of the target then exit tabKey
  --   if target = "" then pass tabKey
  selectNextEmptyFld
end tabKey

on selectNextEmptyFld
  put the short name of the target into tCurFld
  put itemOffset(tCurFld,sFlds) into tStart
  if tStart = the number of items in sFlds and fld (item tStart of sFlds) <> "" then
    put 1 into tStart
  end if
  repeat with x = tStart to the number of items in sFlds
    put item x of sFlds into tFldName
    if fld tFldName = empty then
      select text of fld tFldName
      exit repeat
    end if
  end repeat
end selectNextEmptyFld
Maybe that will get you close.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”