Can buttons work without 'Edit' mode?

Question: Is it possible to have the buttons work when pressed even if the form is NOT in 'Edit' mode?

Specifically, when in Display mode, I would like the user to be able to click these button and have them execute code to change the value of a field.

Thanks.

image

Dear @ParAvion,
The buttons are fully usable, there is no difference between Edit and Display form. What you might have trouble with is to change the value of a field - the fields are not editable on the Display form. The only way that you can do it is if you change values directly in the list via pnpjs methods, for example.

Try the following code in button's Click:

pnp.sp.web.lists.getByTitle('List Name').items.getById(fd.itemId).update({
    Title: 'Test'
});  
fd.field('Title').value = 'Test';

Dear @Nikita_Kurguzov,

I have tried your code but the value won't change. This is what I'm using:

image

Please advise...thanks.

Dear @ParAvion,
What's the name of the current list? Is it Availability or is it something else?

Because you're changing Title field in the request, instead it should be something like this:

pnp.sp.web.lists.getByTitle('Current List Name').items.getById(fd.itemId).update({
    Availability: 'Test'
});  
fd.field('Availability').value = 'Test';

Plus, this code might not work if the field type is special, like Lookup field, for example.

The name of the list is 'Availability'.
The name of the field is also 'Availability'.
The value in the choice field I want to change it to is 'Ready'.

I've got it to work, but it doesn't save the change; it reverts back to the original value. I've added fd.save() but it's not performing a save. Again, I'm trying to accomplish this while in Display mode.

Thoughts?

Thanks.

Dear @ParAvion,
Do you understand what the code is supposed to do?

If you break it apart, it consists of two parts. First part updates the value and saves it:

pnp.sp.web.lists.getByTitle('Availability').items.getById(fd.itemId).update({
    Availability: 'Ready'
});  

Second part, which you can visibly see on the form is just updating the display text, it doesn't save or do anything, this is just visual:

fd.field('Availability').value = 'Test';

Maybe, you can test it with Title field first instead?