set traversal on 10 fields at once?

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
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

set traversal on 10 fields at once?

Post by jalz » Sat Dec 27, 2014 6:14 pm

Hi Guys,

I've got a number of fields that I've set as readonly. I've figured out the code to make them 'focusable' so a user can change the data on my data entry screen. the issue is I have about 10 fields and instead of copying and pasting the set the traversalOn true for each field, is there a shorthand way I can provide a delimited list of fields I want the traversalOn to be and wrap it in a much shorted command?

Thanks as always

Jalz

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: set traversal on 10 fields at once?

Post by Dixie » Sat Dec 27, 2014 7:47 pm

If it was to be for consecutively numbered fields then this might do..

Code: Select all

on mouseUp
   repeat with count = 1 to 10
      set the traversalOn of fld count to true
   end repeat
end mouseUp
If it was to set the traversalOn for different numbered or named fields then this might work for you

Code: Select all

on mouseUp
   put 1,3,5,7,9 into theList
   repeat with count = 1 to the number of items of theList
      set the traversalOn of fld (item count of theList) to true
   end repeat
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: set traversal on 10 fields at once?

Post by dunbarx » Sat Dec 27, 2014 8:20 pm

Hi.

If the fields of interest are not ordered numerically, for whatever reason, I like to assign an identifier that sets them apart. Something like naming them "L1", "L2", "L3", etc. Now it does not matter how many fields you have, or how many of the ones of interest there are, or how they are ordered, or whether you add or subtract to the count of either the good ones or the bad ones:

So you can:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of flds
      if char 1 of the short name of fld y = "L" then set the traversalOn of fld y to "true"
   end repeat
end mouseUp
Craig

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: set traversal on 10 fields at once?

Post by jalz » Sun Dec 28, 2014 10:52 pm

awesome, thanks guys

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

Re: set traversal on 10 fields at once?

Post by SparkOut » Sun Dec 28, 2014 11:08 pm

Another way (which is basically the same as Dixie's but directly uses the field name, which can be forced to resolve by enclosing in brackets):

Code: Select all

put "abc,def,ghi,jkl,mno,pqr,stu,vwx,yza" into tList -- list of field names here
repeat for each item tField in tList
   set the traversalOn of field (tField) to true
end repeat
You can errortrap with a check "if there is a field (tField) then..." as well if need be

Post Reply