View Full Version : ReadOnly Pains.
drahkar
January 11th, 2010, 23:45
I can't seem to get anything to actually be read only. No matter what I set onto it, its always editable and saves the information entered. Can someone show an example that they've used to make a template readonly that works? I'm just not sure what it is I'm not doing correctly with it. :confused:
Thanks!
Foen
January 12th, 2010, 06:24
The setReadOnly function does pretty much what you'd expect, and applies to string and number fields. You need to call it with a parameter, to turn readonly mode on or off:
setReadOnly(true) - makes a control readonly
setReadOnly(false) - makes a control read/write
If you are having difficulties, try inserting print statements into your code: it could be that the code isn't executing how/when you expect. Otherwise, please feel free to post a few snippets and I'd be happy to look at them.
Cheers
Stuart
Oberoten
July 24th, 2011, 00:51
Any way to get this to work with a stringfield instead of a stringcontrol?
- Obe
StuartW
July 24th, 2011, 05:48
It should already work with stringfield, because stringfield inherits from stringcontrol. I've not tried it though, and by implication from your question it doesn't do what you expect!
Another one to try is setEnabled(false), but I can't remember if this disables editing or just stops a control from receiving UI events (such as onClick and onDrop).
Finally, with database-bound controls (such as stringfield), removing the user's ownership of the underlying database node will also make a control read-only.
Stuart
Sorcerer
July 24th, 2011, 12:05
I am using setReadOnly() for stringfields much as described above and it works perfectly for me.
I also use a variation which checks if the User.isHost() first so that the fields can be set readonly for players, but still be editable by the GM.
another option is to set the containing DatabaseNode to static
if not User.isHost() then
getDatabaseNode().setStatic(true)
end
this can be applied to a single field, but is obviously more suited to covering an entire window.
Oberoten
July 24th, 2011, 13:52
Funny... that one worked pefectly.
Now just to set the lock so it can be locked or unlocked by clicking a button. (Since the NPC skill field is made out of strings... I'd much prefer to have it not edited unless you need to edit it :) )
Thank you :)
- Obe
Zeus
July 24th, 2011, 15:16
Funny... that one worked pefectly.
Now just to set the lock so it can be locked or unlocked by clicking a button. (Since the NPC skill field is made out of strings... I'd much prefer to have it not edited unless you need to edit it :) )
Thank you :)
- Obe
Your welcome to use my lock/hide field functionality from my 4E extensions Obe. If you check out my 4E Personalities or 4E Items extensions you can re-use the control bar, icon assets and LUA script as well (if it helps).
Oberoten
July 25th, 2011, 00:00
Many thanks for the kind offer. :) I shall go in dissecting and learn some new tricks I hope. :)
- Obe
pelinorerevived
September 30th, 2011, 20:09
another option is to set the containing DatabaseNode to static
if not User.isHost() then
getDatabaseNode().setStatic(true)
end
this can be applied to a single field, but is obviously more suited to covering an entire window.
Maybe I'm a dufus, but I can't get this to work. I tried to test it on this piece of code:
<labeledstring name="name">
<anchored>
<to>overviewframe</to>
<position>insidetopleft</position>
<offset>0,25</offset>
<size>
<width>430</width>
<height>20</height>
</size>
</anchored>
<anchorto>overviewframe</anchorto>
<height>20</height>
<label>Name</label>
<script>
if not User.isHost() then
getDatabaseNode().setStatic(true)
end
</script>
<tabtarget>
<next>culture</next>
<prev>name</prev>
</tabtarget>
</labeledstring>
I get the following error:
Script Error: [string"charsheet_main:name"]:1: attempt to index global 'User' (a nil value].
Can anyone tell me what I'm doing wrong?
Zeus
September 30th, 2011, 20:17
Try
function onInit()
if not User.isHost() then
getDatabaseNode().setStatic(true)
end
end
pelinorerevived
September 30th, 2011, 20:38
Thanks. Worked like a charm. Although it caused some odd behaviours in the labeledstring, depending on where I placed it (either parts of the labeledstring failed to display or the whole thing).
No matter, I only put it there to test it. Where I really wanted it to work was in the numberfields to prevent *ahem* accidental changes to the character sheet.
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.