Organize multi-choice user inputs by separate line (not comma)
-
08-02-2021 - |
سؤال
I would like to format a column, so that when a user selects multiple choices, each choice is displayed on a single line rather than separated by comma (,).
I'm looking to leverage JSON formatting for this.
المحلول
Try using below JSON code on your choice field:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=join(@currentField, '\n')"
}
Official documentation: Use column formatting to customize SharePoint.
Reference for operators you can use in JSON formatting, JSON formatting - Operators.
How join()
works:
join() takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string.
Returns a string concatenation of the array values separated by the separating string.
Example for multi-select choice field:
"txtContent": "=join(@currentField, ', ')"
--> This will result in Apple, Orange, Cherry
(depending on the selected values)
Example for multi-select person field:
"txtContent": "=join(@currentField.title, '|')"
--> This will result in Chris Kent|Vesa Juvonen|Jeff Teper
(depending on the selected persons names).
نصائح أخرى
You can use this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=join(@currentField, '\n'"
}
A little explanation:
join: takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string. Returns a string concatenation of the array values separated by the separating string. - Only available in SharePoint Online
"txtContent": "=join(@currentField, ', ')" might result in "Apple, Orange, Cherry" (depending on the selected values)
"txtContent": "=join(@currentField.title, '|')" might result in "Chris Kent|Vesa Juvonen|Jeff Teper" (depending on the selected persons)