Forum Discussion
Conditional formatting for blank FORM fields
I encounter the same problem when attempting to insert text if a date field is empty.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(@currentField, @currentField.displayValue, 'unset')"
}
Unfortunately, it appears that Microsoft has chosen to apply custom formatting in a form view only when the field contains data. The sp-custom-formatted-ReactFieldEditor-Core-Display element does not activate when the field is empty.
We will have to wait until Microsoft alters this behavior.
The below information is found here: https://ganeshsanapblogs.wordpress.com/2021/06/20/sharepoint-json-formatting-check-if-date-and-time-column-is-blank-empty/
to check if date & time column is blank/empty using SharePoint JSON formatting, you have to use either of below workarounds:
Using Number() function
You can use Number(DateTimeColumn) == 0 to check if the date & time column is blank or not.
Example
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=if(Number([$DueDate]) == 0, 'Blank Date', if([$DueDate] < @now, 'Expired', 'Active'))", "attributes": { "class": "=if(Number([$DueDate]) == 0, 'sp-field-severity--warning', if([$DueDate] < @now, 'sp-field-severity--blocked', 'sp-field-severity--good'))" } }
Where [$DueDate] is an https://ganeshsanapblogs.wordpress.com/2023/04/17/how-to-find-the-internal-name-of-sharepoint-columns/.
You can also find above JSON at list formatting samples on GitHub: https://github.com/pnp/List-Formatting/tree/master/column-samples/date-check-blank-format
Using toString() function
You can use toString(DateTimeColumn) == '' to check if the date & time column is blank or not.
Example
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=if(toString([$DueDate]) == '', 'Blank Date', if([$DueDate] < @now, 'Expired', 'Active'))", "attributes": { "class": "=if(toString([$DueDate]) == '', 'sp-field-severity--warning', if([$DueDate] < @now, 'sp-field-severity--blocked', 'sp-field-severity--good'))" } }
Simplest way
You can also check if date & time column is blank/empty using below JSON:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=if(@currentField, @currentField, 'Blank Date')", "attributes": { "class": "=if(@currentField, 'sp-field-severity--good', 'sp-field-severity--warning')" } }
SharePoint JSON formatting – Check if date and time column is blank or empty
Learn More
- https://ganeshsanapblogs.wordpress.com/2021/01/10/working-with-sharepoint-online-microsoft-list-comments-using-json-formatting/
- https://ganeshsanapblogs.wordpress.com/2022/08/22/sharepoint-replace-all-occurrences-of-substring-in-a-string-using-json-formatting/
- https://ganeshsanapblogs.wordpress.com/2022/08/23/sharepoint-highlight-selected-list-item-row-using-json-formatting/
- https://ganeshsanapblogs.wordpress.com/2022/11/12/download-image-from-sharepoint-image-column-using-json-formatting/
- https://ganeshsanapblogs.wordpress.com/2022/11/10/sharepoint-online-download-files-using-json-formatting/