Applying Column Formats to Multi-line Text Fields

Multi-line text columns don’t provide the standard “Format this column” option under Column settings in the modern list view column menu. They used to, but now they don’t. Fortunately, there is still a way to apply column formatting to these fields!

There are 2 ways in within the interface to apply column formatting for a column (you can also do it programatically). The easiest and most common way is to use the “Format this column” option mentioned above, but it’s not the only way! The advanced settings for a column provide an additional spot where you can paste your formats. Aw yeah!

The Format

I’m using the text-wrap-format sample from PnP created by Aaron Miao. This is a great format for when you really want to see your full text (instead of the cut-off fade provided by default). I’ve modified the sample slightly to apply the primary theme color for the text to make it even more obvious. Here’s the full format:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "white-space": "normal",
    "padding": "11px 0"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary"
  }
}

Applying the Format

Here’s what our list view looks like before applying column formatting to the multi-line text field, “Synergy”:

To apply column formatting to a multi-line text column:

  • Navigate to the List Settings (Site Actions > List Settings):
  • Choose the multi-line column from the column settings
  • Scroll to the bottom of the multi-line column settings and paste your format in the Column Formatting section:
This same option is also available for site columns!
  • Click OK, then return to your list view and refresh to see the format applied:
The blue is the theme color and was added to the sample just to make it more obvious a format was applied. The key thing to notice is that the full text is now shown.
  • Weep at the beauty of thy column!

NOTE – List Formatting encodes values prior to rendering which makes the use of enhanced (rich text) multi-line fields basically unusable in your formats. These values come back as HTML and that HTML will be encoded and then displayed inline with your values. It is NOT recommended to use Rich text fields in your formats.

Update

See this demoed on the PnP Call (Live from MVP Summit):

Love List Formatting?

Join the Bi-weekly (every other Thursday) SharePoint Patterns and Practices special interest group for general development call where I will be presenting a new List Formatting Quick Tip on each call!

Also, come get the full picture in my sessions about List Formatting at the SharePoint Conference in Las Vegas in May, or the European Collaboration Summit in Germany in May:

5 thoughts on “Applying Column Formats to Multi-line Text Fields

  1. I’m creating a List in SharePoint and I want to be able to create a Text limit for a Multi Line field. In the List settings, you can set the limit to however number of lines, but that is not really helpful. I’ve done experimenting, and there doesn’t seem to be a limit of characters. I want to be able to limit the user to add no more than 1000 characters in this field. I’ve tried searching online for the JSON code for this, but I can’t for the life of me get the examples that I’ve found to actually work.

    I have the below code for formatting my column a certain way (show only a certain number of lines in the list, also size 11). But I can’t get the maxLength to work… I’ve tried variations of txtArea, etc… but it doesn’t work. I can still put more than 1000 characters in that field.

    {
    “$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
    “elmType”: “div”,
    “txtContent”: “=substring(@currentField, 0, 140) + ‘…'”,
    “style”:{“font-size”: “11pt”,
    “txtArea”: “=maxlength, 1000”}
    }

    • Unfortunately, I’m not aware of a way to accomplish what you are trying to do using out of the box configuration. Column Formatting like you’ve posted will only affect the display of a list item and will have no effect on the edit experience. Generally, I would look to Column Validation, but unfortunately that doesn’t support multi-line text fields. In a classic view you could handle a preSaveAction using custom javascript, but that is not an option in modern list views. Your best bet is to customize the list form using Power Apps. From there you can change the MaxLength property of the datacard to 1000 (default is to pull that from the datasource).

Leave a comment