cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

How can I change "ReadOnly" attribute of Textbox widget dynamically?

shasegawa
1-Visitor

How can I change "ReadOnly" attribute of Textbox widget dynamically?

When I use built-in textbox widget, how can I change "ReadOnly" attribute of the textbox widget depends on login user? For example, only users belongs to Administrator group can change value of text box and generic user only can see the value.

ACCEPTED SOLUTION

Accepted Solutions

Hi Yamini, I don't think that this was what he was asking for.

Hi Satoshi, unfortunately ReadOnly property on TextBox Widget isn't bindable, then you can't set ReadOnly/Not ReadOnly on runtime.

What I would do it's add two widgets the same place, one TextBox and a ValueDisplay, and show/hide them ( visibility property it's bindable ) depending on the current user permissions.

Of course, you have to build a custom service which tells you if the user has ReadOnly or Read/Write access to the given property. This can be done checking the Group's ownership of the user, or as pointed out by Yamini, setting according permissions to the property and checking on this custom service which kind of access has the user on the given property.

To check current user's groups:

var userGroups = Resources["CurrentSessionInfo"].GetCurrentUserGroups();

To check user's permissions to a given property:

var hasReadPermission = me.CheckPermission({ name: "propertyName", type: "PropertyRead" });

var hasWritePermission = me.CheckPermission({ name: "propertyName", type: "PropertyWrite" });

View solution in original post

3 REPLIES 3
ytella
17-Peridot
(To:shasegawa)

Hi Satoshi, Click on your desired Thingtemplate or thing and select Run Time link in the explorer. Now in (All Properties, Events, and services )-->type the group or user you want to set the permissions.  Select the green dot to allow and red dot to deny.  You can also set permissions to individual properties in (property,Service or Event Overrides). Let me know if this doesn't solve your problem .

Hi Yamini, I don't think that this was what he was asking for.

Hi Satoshi, unfortunately ReadOnly property on TextBox Widget isn't bindable, then you can't set ReadOnly/Not ReadOnly on runtime.

What I would do it's add two widgets the same place, one TextBox and a ValueDisplay, and show/hide them ( visibility property it's bindable ) depending on the current user permissions.

Of course, you have to build a custom service which tells you if the user has ReadOnly or Read/Write access to the given property. This can be done checking the Group's ownership of the user, or as pointed out by Yamini, setting according permissions to the property and checking on this custom service which kind of access has the user on the given property.

To check current user's groups:

var userGroups = Resources["CurrentSessionInfo"].GetCurrentUserGroups();

To check user's permissions to a given property:

var hasReadPermission = me.CheckPermission({ name: "propertyName", type: "PropertyRead" });

var hasWritePermission = me.CheckPermission({ name: "propertyName", type: "PropertyWrite" });

Hi Carlos,

Thank you for your support. Perhaps, I can realize what I wanted to do in the way you suggested.

Thank you very much.

Announcements


Top Tags