Back to column formats
Column formattingSharePoint Online

Yes/No Column Toggle

This sample demonstrates changing the value of the Yes/No column to a toggle. Three different versions of the sample are provided (Toggle, Icon, Emoji).

Yes/No Column Toggle formatting preview
Sample preview ยท View original animation

Copy. Apply. Make it yours.

Get this format

3 definitions

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex",
    "width": "100%",
    "height": "100%",
    "align-items": "center"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "flex",
        "width": "60px",
        "height": "30px",
        "border-radius": "15px",
        "align-items": "center",
        "flex-direction": "row",
        "justify-content": "=if(@currentField , 'flex-end' , 'flex-start')",
        "cursor": "pointer"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YesNoColumnInternalName": "=if(@currentField , '0' , '1' )"
        }
      },
      "attributes": {
        "class": "=if(@currentField , 'ms-bgColor-themePrimary' , 'ms-bgColor-neutralTertiaryAlt')"
      },
      "children": [
        {
          "elmType": "div",
          "txtContent": "=if(@currentField , '๐Ÿ˜Š' , '๐Ÿ˜”')",
          "style": {
            "font-size": "18px",
            "margin-left": "4px",
            "margin-right": "4px",
            "padding-bottom": "2px"
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates changing the value of the Yes/No column to a toggle. Three different versions of the sample are provided (Toggle, Icon, & Emoji). Also, this sample uses the setValue of customRowAction to update the field. You need to set the actionInput to the internal name of the column to be updated.

screenshot of the sample

View requirements

This format can be applied to a Yes/No column.

Sample

Solution Author(s)
yesno-toggle-format.json Tetsuya Kawahara
yesno-toggle-icon-format.json Tetsuya Kawahara
yesno-toggle-emoji-format.json Tetsuya Kawahara

Version history

Version Date Comments
1.0 April 29, 2021 Initial release
1.1 November 21, 2021 Modified to update item using setValue

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes

There is also a way to implement this with SPFx Extension, available from PnP: React Toggle Field Customizer