Forum Discussion
How can users change Yes/No columns?
- Apr 12, 2023
dgajohnson try using JSON sample given here: Yes/No Column Toggle
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
dgajohnson Try using JSON column formatting for your Yes/No column like below:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"inlineEditField": "@currentField",
"txtContent": "=if(@currentField,'Yes','No')"
}
This will allow users to edit the column value inline from list/table view itself without going to properties form:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
- sam77meyerNov 27, 2023Copper Contributor
Is there a way to adjust this code to have it only apply to certain content types and/or apply only if another column meets a requirement?
My problem:
I have a Sharepoint list which contains both folders and excel files. With the current JSON, it automatically applies the pre-set value to all entities in the list where I only want it to show next to the excel files to avoid confusion.
- ganeshsanapNov 28, 2023MVP
sam77meyer Yes, you can hide the JSON formatting for folders using visibility or display properties inside style property.
Example:
"style": { "visibility": "=if([$ContentType] == 'Folder', 'hidden', 'visible')" },Where ContentType is the internal name of your SharePoint list column which you have to use in this format: [$ContentType]. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?
You may have to show the Content Type column in your library view to read it's value in JSON.
Above JSON snippet is taken from here (full JSON example available): SharePoint Online: Download files using JSON Formatting
Please consider giving a Like if my post helped you in any way.
- sam77meyerNov 28, 2023Copper Contributor
Thanks for the reply ganeshsanap
Still having trouble after using the following JSON - only change I can get using variations of this code is it hiding the Yes/No for every content type.
- dgajohnsonApr 12, 2023Copper Contributor
ganeshsanap thank you, this is working!
Do you know of a way to make it so that you can change the value with only one click? With this formatting the user has to click the cell, wait for it to load, and then change its value. Do you know of a method where the user could change the value with just one click?- ganeshsanapApr 12, 2023MVP
dgajohnson try using JSON sample given here: Yes/No Column Toggle
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
- dgajohnsonApr 12, 2023Copper Contributor
ganeshsanap thanks! I found that one too. I ended up using this:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "button", "txtContent": "=if(@currentField, 'Yes', 'No')", "customRowAction": { "action": "setValue", "actionInput": { "MyCustomField": "=if(@currentField, false, true)" } }, "style": { "background-color": "=if(@currentField, '#0078d4', '#ffffff')", "color": "=if(@currentField, '#ffffff', '#333333')", "border": "none", "cursor": "pointer", "padding": "4px 12px", "border-radius": "4px" } }ChatGPT made the style, and I pulled the customRowAction parameter from that repo.