Preventing users from editing fields

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
steveharman
Posts: 26
Joined: Fri Apr 12, 2013 11:03 am

Preventing users from editing fields

Post by steveharman » Wed May 29, 2013 9:45 am

Hi,

I have some screens in my app which display data from a web service, that some users should be able to EDIT but other users should only be able to VIEW.

Clearly it's easy to set the 'Disabled' property of fields to prevent editing, but this seems to have the side effect of dimming the field contents so they're difficult to read?

Can anyone suggest another way I can make my fields editable for 'x' user but not for 'y'' user? (I'll be handling which user is which, I just need an idea for preventing field editing).

Thanks,

Steve

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Preventing users from editing fields

Post by Simon » Wed May 29, 2013 10:06 am

Use "lockText" be sure to set autoHilite in the properties inspector.

Simon
Attachments
lock.zip
LC 6.0
(621 Bytes) Downloaded 258 times
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

steveharman
Posts: 26
Joined: Fri Apr 12, 2013 11:03 am

Re: Preventing users from editing fields

Post by steveharman » Wed May 29, 2013 10:14 am

Perfect - thanks Simon. I couldn't see it for looking! :-)

Cheers,

Steve

steveharman
Posts: 26
Joined: Fri Apr 12, 2013 11:03 am

Re: Preventing users from editing fields

Post by steveharman » Wed May 29, 2013 10:27 am

Although - is LockText possible if I were to group my fields? After grouping some fields I couldn't see a property in the Inspector.

Just laziness (efficiency?) on my part, but it would be great to be able to group my 20 or so fields into one and set / un-set the LockText property of the group instead of setting each field. If it's available....

Cheers,

Steve

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Preventing users from editing fields

Post by Simon » Wed May 29, 2013 10:33 am

Down at the bottom of the Inspector is Behavior.
I think the command is:
set the behavior to fld 1
Then they all act like fld 1 and you only have to change fld 1 :)

Check the dictionary on behavior.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Preventing users from editing fields

Post by Klaus » Wed May 29, 2013 12:23 pm

Hi Steve,

you can select all of your fields and then set the LOCKTEXT (and other props)
for ALL of them in the inspector!

P.S.
A "behavior" is a SCRIPT that you can set and has nothing to do with other object properties
like "locktext" etc. :-)


Best

Klaus

steveharman
Posts: 26
Joined: Fri Apr 12, 2013 11:03 am

Re: Preventing users from editing fields

Post by steveharman » Wed May 29, 2013 12:29 pm

That's a thought Klaus.

Any way of selecting 'all fields' or a range of fields from script? Eg; "set the LockText of AllFields on this card to true" ? Or "set the LockText of fields 1 to 10 to true" ?

Steve

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Preventing users from editing fields

Post by Klaus » Wed May 29, 2013 12:39 pm

Hi Steve,

sure, you need to LOOP through all the fields:

Code: Select all

...
## LOOP by number
repeat with i = 2 to 22
  set the locktext of fld i to TRUE
end repeat
...

## Or if you named the fields like "contentfield1" to "contentfield33" but they are not ordered on the card
## Hint: A good naming convention can save a LOT of time" :-)
## Hint 2: PARENS are MANDATORY when concatenating object names!
repeat with i = 1 to 33
  set the locktext of fld ("contentfield" & i) to FALSE
end repeat
...
Best

Klaus

steveharman
Posts: 26
Joined: Fri Apr 12, 2013 11:03 am

Re: Preventing users from editing fields

Post by steveharman » Wed May 29, 2013 12:47 pm

Superb, thanks Klaus. I am going to have to stop trying to over-think solutions in LiveCode. Some things are SO easy.

Especially when someone such as yourself points them out. LOL! :-)

Regards,

Steve

Post Reply