People field - unable to disable

Hi!

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.

image

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":

fd.field('ApprovedBy').value = props[i].Value;
fd.field('ApprovedBy').ready().then(function (field) {
  if (field.value) {
     field.disabled = true;
}

It would be great to know why, but of course few lines more in code does not make any big trouble.

Hello @Marcin,

How do you call the updateCurrentUserInfo() function?

Hi,

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.

Regards

@Marcin,

I'm sorry, I couldn't reproduce the issue on my form. The function woks just fine.

Try to debug your code, maybe there is a typo in the field internal name or something else.

Or simply use the this code:

fd.field('ApprovedBy').value = props[i].Value;
fd.field('ApprovedBy').ready().then(function (field) {
  if (field.value) {
     field.disabled = true;
}

I seem to have the same issue in SharePoint Online: I cannot see what is wrong with the below code:

    fd.field('ProgrammeOwner').ready().then(function(field) {
        field.disabled = true;
    });

this returns a bug in the console:

TypeError: Cannot read properties of null (reading 'enable')

I've reduced my code down to this line, so it is not being affected by any other JS.

Seems like a bug.

Hello @abolam,

I have tested the code on my form and it disables the field without any errors.

What version of the desktop designer and app package are you using?

You can find the app package version in the Page Source:
image

Hi mnikitina,

I think I've just spotted a typo elsewhere which may have caused this confusion, apologies, working now. :blush:

Kind regards

Andy

1 Like