Hi there,
I hope this is an easy one. I have tried but my JS code is not working.
I have a button that I only want to appear when a sharepoint text field = "No" If it is "Yes" the button needs to be hidden.
Appreciate the help.
Hi there,
I hope this is an easy one. I have tried but my JS code is not working.
I have a button that I only want to appear when a sharepoint text field = "No" If it is "Yes" the button needs to be hidden.
Appreciate the help.
Just to be clear the SP field is a Text field not a Yes/No field. And I only want my button to be visible when text inside the SP Text field = "Yes"
Hello @mhannaway,
You can show/hide control dynamically using the code:
function showHideButton() {
if(fd.field('Field1').value === 'Yes') {
//show control
fd.control('Button1').hidden = false;
}
else {
//hide control
fd.control('Button1').hidden = true;
}
}
//call function on form load
showHideButton();
//call function on field change
fd.field('Field1').$on('change', showHideButton)
Thanks @mnikitina
For some strange reason it isnt working. I am pasting the below code into the JS editor. If the field 'HiringManagerApprovalButton' is a 'No' I want the button to show. Does the SP field have to show in the form for it to work?
function showHideButton() {
if(fd.field('HiringManagerApprovalButton').value === 'No') {
//show control
fd.control('Button2').hidden = false;
}
else {
//hide control
fd.control('Button2').hidden = true;
}
}
//call function on form load
showHideButton();
//call function on field change
fd.field('HiringManagerApprovalButton').$on('change', showHideButton)
If you are using forms for SharePoint Online, you must place the code inside the spRendered() event like so:
fd.spRendered(function(vue) {
function showHideButton() {
if (fd.field('HiringManagerApprovalButton').value === 'No') {
//show control
fd.control('Button2').hidden = false;
} else {
//hide control
fd.control('Button2').hidden = true;
}
}
//call function on form load
showHideButton();
//call function on field change
fd.field('HiringManagerApprovalButton').$on('change', showHideButton)
});
Thank you for clarifying. Im sorry @mnikitina I'm relatively new to code and trying my best to learn. Attached is a screenshot of what I pasted, but it still wont work. I tried pasting it above as well as below all my other code in JS editor and it wouldnt work.
Not a problem, we all started somewhere.
Please share the screenshot of all errors from the browser console(F12) that you get on form load and when changing the field value.
Thanks @mnikitina
See screenshot of error below. Not sure what the other failed to load resource errors are but the error in relation to the show hide button is showing.
Thank you!
Most likely the field name in the code is invalid. You need to double check the field internal name and update it. You can find the internal name in the designer:
Thanks @mnikitina
Turns out the SP field had to be in the form itself. So added the field and just hid it and it worked.
Thank you so much.