1

New to JSON. Trying to write JSON when ever a free form text field is filled out, have this but don't know how to get it to highlight when anything is entered. I do not want highlights on blank items:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "debugMode": true,
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField == '','sp-field-severity--good','')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
} 
1
  • Can you please explain what are the conditions to highlight the cell? Commented Aug 27, 2020 at 2:04

2 Answers 2

1

Just change your code to this:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "debugMode": true,
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField == '','','sp-field-severity--good')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
} 

enter image description here

1

You need to add a style parameter to apply styling and this can be conditional, as you see below. In style or class I have made certain changes which should work for you

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "debugMode": true,
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField,'sp-field-severity--good','')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px",
        "color": "=if([@currentField] == '', 'red', 'black')"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
} 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.