SOLVED

List - Conditional formatting for blank text field

Copper Contributor

I'm using Lists via Teams (Office 365). I've got a list with a "single line text" column. I'd like to add some conditional formatting if the column contents are not blank.

 

The only options I see in the conditional formatting dialog are "is equal to" and "is not equal to", so I picked "is not equal to", but it won't accept an empty value in the "choose a type or value" box (which is a plain text field, it's not a dropdown). I tried empty single quotes and empty double quotes but that didn't work.

 

JasonC4_0-1648828293369.png

 

How do I do this?

 

Thanks!!

2 Replies
best response confirmed by JasonC4 (Copper Contributor)
Solution

@JasonC4 

You might want to open the 'Advanced mode' linked at the very bottom above the save button.
In here the operand accepts double quotes for 'blank fields' (line 18).

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "[$SingleLineOfText]",
            ""
          ]
        },
        "sp-css-backgroundColor-BgGold",
        ""
      ]
    }
  },
  "txtContent": "[$SingleLineOfText]"
}

 

@Micca0815 This works great on a list view; however, It does not work for any of the form views.  I've tried multiple methods to try to highlight a blank field (number or text) on a form field but nothing has worked so far.  Do you know why this is?

 

List View with formatting looks great.

Shaune1215_0-1712949195445.png

Form View formatting is not present.  Instead SP displays an em dash?

Shaune1215_1-1712949245368.png

 

If I change the formula to look for any value, for example "test123", the formatting does show up on the form view.  The only thing that does not work is blank fields on the form view.  Any advice?

1 best response

Accepted Solutions
best response confirmed by JasonC4 (Copper Contributor)
Solution

@JasonC4 

You might want to open the 'Advanced mode' linked at the very bottom above the save button.
In here the operand accepts double quotes for 'blank fields' (line 18).

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "[$SingleLineOfText]",
            ""
          ]
        },
        "sp-css-backgroundColor-BgGold",
        ""
      ]
    }
  },
  "txtContent": "[$SingleLineOfText]"
}

 

View solution in original post