[xwiki-users] Assign user list property
I have a class called TaskManager with a property called Reporter that is of a "List of Users" type. What I am trying to do is assign the current user to the Reporter property when a new document is created so that the user does not have to select himself from the user list control, but I would like this field to also remain as read-only so the user cannot change it to someone else. Using the following code in the TaskManagerSheet, the property gets populated on new, however when it is saved it disappears (not saved into the property). I have narrowed it down to the problem being the 'view' parameter in the $doc.display() function which makes it readonly, however because of this it is not being saved. Is there a way to set a value on new but retain a read-only status Here is the code that I am using: #set ($discard = $doc.use('TaskManager.TaskManagerClass')) #if($doc.isNew()) $doc.set('reporter',$context.user) #end : $doc.display('reporter', view)
Just put a $doc.display('reporter', 'hidden') somewhere in your form, after you set its value. It will generate an hidden input field that will ensure the reporter is saved. Hope this helps, Marius On Thu, Jan 16, 2014 at 12:12 AM, Kelly Steinke <[email protected]> wrote:
I have a class called TaskManager with a property called Reporter that is of a "List of Users" type. What I am trying to do is assign the current user to the Reporter property when a new document is created so that the user does not have to select himself from the user list control, but I would like this field to also remain as read-only so the user cannot change it to someone else.
Using the following code in the TaskManagerSheet, the property gets populated on new, however when it is saved it disappears (not saved into the property). I have narrowed it down to the problem being the 'view' parameter in the $doc.display() function which makes it readonly, however because of this it is not being saved. Is there a way to set a value on new but retain a read-only status
Here is the code that I am using:
#set ($discard = $doc.use('TaskManager.TaskManagerClass')) #if($doc.isNew()) $doc.set('reporter',$context.user) #end : $doc.display('reporter', view)
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Thanks Marius, I don't know why I didn't think of that works like a charm! ----- Original Message ----- From: "Marius Dumitru Florea" <[email protected]> To: "XWiki Users" <[email protected]> Sent: Thursday, January 16, 2014 8:43:54 AM Subject: Re: [xwiki-users] Assign user list property Just put a $doc.display('reporter', 'hidden') somewhere in your form, after you set its value. It will generate an hidden input field that will ensure the reporter is saved. Hope this helps, Marius On Thu, Jan 16, 2014 at 12:12 AM, Kelly Steinke <[email protected]> wrote:
I have a class called TaskManager with a property called Reporter that is of a "List of Users" type. What I am trying to do is assign the current user to the Reporter property when a new document is created so that the user does not have to select himself from the user list control, but I would like this field to also remain as read-only so the user cannot change it to someone else.
Using the following code in the TaskManagerSheet, the property gets populated on new, however when it is saved it disappears (not saved into the property). I have narrowed it down to the problem being the 'view' parameter in the $doc.display() function which makes it readonly, however because of this it is not being saved. Is there a way to set a value on new but retain a read-only status
Here is the code that I am using:
#set ($discard = $doc.use('TaskManager.TaskManagerClass')) #if($doc.isNew()) $doc.set('reporter',$context.user) #end : $doc.display('reporter', view)
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (2)
-
Kelly Steinke -
Marius Dumitru Florea