In Sharepoint 2019 I have strange problem with disabling people picker field. Disabling doesn't work. Of course I went through this community and found some solutions, but it doesn't help.
I have a function to call when I want to fill proper field (depending on status name.
function updateCurrentUserInfo(status) {
let statusEmail = status + 'Email'
const webQuery = pnp.sp.profiles.myProperties.get();
return webQuery.then(function (result) {
const props = result.UserProfileProperties;
for (var i = 0; i < props.length; i++) {
switch (props[i].Key) {
case 'PreferredName':
fd.field(status).value = props[i].Value;
fd.field(status)
.ready()
.then(function (field) {
if (field.value) {
field.disabled = true;
}
});
break;
case 'WorkEmail':
fd.field(statusEmail).value = props[i].Value;
break;
}
}
});
}
This function works great and I can see proper persons in their fields. fd.field('fieldname').disabled return true in browsers console. They are later successfully saved, but field.disabled = true; doesn't work at all.
So function works (sets value and disable attribute) but I can not see this and you can enter another person in the field.
I have no clue what is wrong.
Probably, I have answered partly by myself.
If I use field name as parameter in a function (like above) it is not working.
If I use field name "directly":
I named all 'users' fields with the name of status in process. So if we have path of actors 'registration', 'approval', 'cashier', 'accountant', there are relevant people type fields (and text fields for email).
So in Edit Form in fd.spRendered() I call relevant function which sets/hides fields for particular users:
if (fd.field('status').value == 'Approval') {
statusApproval()
} else if (fd.field('status').value == 'Cashier') {
statusCashier()
} else if (fd.field('status').value == 'Accountant') {
statusAccountant()
} else {
doSomethingElse()
}
And for example function for status of Cashier is:
function statusCashier() {
//set some fields
//hide some fields
updateCurrentUserInfo('Cashier')
//do something else
}
So simple. Function updateCurrentUserInfo() works, the only trouble is the field is not disabled.
I would appreciate if you can point what I did wrong.