New Form: When the people picker field is set to read only, the field is not displayed
Hello all,
i add a script to a people picker field, so that the logged in user is automatically entered. When i set the field to read only, it is not displayed. Can I use a script or what can I do?
Here is my script:
// Load current user login
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
// Set user login
fd.field('User_x0020_name').control().value(user.get_title());
// Run validation by emulating validation image click
fd.field('User_x0020_name').control()._el().find('a:eq(0)').click();
});
}), "SP.js");
Best wishes and take care
Tom
i add a script to a people picker field, so that the logged in user is automatically entered. When i set the field to read only, it is not displayed. Can I use a script or what can I do?
Here is my script:
// Load current user login
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
// Set user login
fd.field('User_x0020_name').control().value(user.get_title());
// Run validation by emulating validation image click
fd.field('User_x0020_name').control()._el().find('a:eq(0)').click();
});
}), "SP.js");
Best wishes and take care
Tom
Hello Tom,
It is not possible to set the people picker field value when the field is disabled. So you need to enable it first, populate with the user name and disable.
It is not possible to set the people picker field value when the field is disabled. So you need to enable it first, populate with the user name and disable.
Code: Select all
//enable field
fd.field('User_x0020_name').readonly(false);
// Load current user login
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
// Set user login
fd.field('User_x0020_name').control().value(user.get_title());
// Run validation by emulating validation image click
fd.field('User_x0020_name').control()._el().find('a:eq(0)').click();
});
}), "SP.js");
//disable field
fd.field('User_x0020_name').readonly(true);
-
- Information
-
Who is online
Users browsing this forum: No registered users and 12 guests