Skip to content

Commit 85f55de

Browse files
Merge pull request SharePoint#7495 from shagra-ms/shagra/docs-edit-actions
Support setValue and inlineEditField
2 parents 28cfc44 + c8f2da3 commit 85f55de

File tree

3 files changed

+156
-2
lines changed

3 files changed

+156
-2
lines changed

docs/declarative-customization/formatting-advanced.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,106 @@ The following image shows a list with a Gallery layout referencing the Category
254254
}
255255
}
256256
```
257+
## Inline Editing
258+
259+
With inline editing, formatters have the ability to load field editors to edit field data on an item.
260+
Users need to have edit permissions on the list item and the field type should belong to set of supported types for this feature to work.
261+
262+
A special json property `inlineEditField` is used with value as the field internal name __`[$FieldName]`__ at the target element in the json.
263+
264+
```json
265+
{
266+
"elmType": "div",
267+
"inlineEditField": "[$FieldName]",
268+
"txtContent": "[$FieldName]"
269+
}
270+
```
271+
<br />
272+
273+
![Inline Editing using inlineEditField property](../images/sp-columnformatting-inline-editing.gif)
274+
275+
This allows the users to edit items in-place, within the view, without navigating away to grid based editing or to a item edit form.
276+
277+
### Supported Field Types
278+
List of supported field types for inline editing
279+
- Single line text
280+
- Multi line text (without RTF)
281+
- Number
282+
- DateTime
283+
- Choice and MultiChoice
284+
- User and Multi user
285+
- Lookup
286+
287+
### Hover Borders and Customizations
288+
The inline editing adds a hover border on the elements to indicate these elements have an associated action. The default border is `neutralSecondary` , and on click, the editor appears with a `themePrimary` border. These border colors can be overriden via setting style on the same element with `inlineEditField` by using some special attributes - `--inline-editor-border-width`, `--inline-editor-border-style`, `--inline-editor-border-radius` and `--inline-editor-border-color`.
289+
290+
```json
291+
{
292+
"elmType": "div",
293+
"inlineEditField": "[$FieldName]",
294+
"txtContent": "[$FieldName]",
295+
"style": {
296+
"--inline-editor-border-color": "transparent transparent red transparent",
297+
"border-color": "gray",
298+
"border-width": "1px",
299+
"border-style": "solid"
300+
}
301+
}
302+
```
303+
304+
## Set multiple field values of an Item using customRowAction
305+
306+
With the new `setValue` `customRowAction`, formatters can render action buttons which modify the item internally without opening editors or forms. `setValue` also allows setting multiple field values of the item at once.
307+
308+
The below JSON will set value of `FieldInternalName_1`, `FieldInternalName_2` and `FieldInternalName_3`with the values provided.
309+
310+
```json
311+
{
312+
"elmType": "div",
313+
"txtContent": "[$FieldName]",
314+
"customRowAction":{
315+
"action": "setValue",
316+
"actionInput": {
317+
"FieldInternalName_1": "FieldValue_1",
318+
"FieldInternalName_2": "FieldValue_2",
319+
"FieldInternalName_3": "=if([$Status] == 'Completed', 'yes', 'no')"
320+
}
321+
}
322+
}
323+
```
324+
325+
### Supported Field Types
326+
- Single line text
327+
- Multi line text (without RTF)
328+
- Number
329+
- DateTime
330+
- Choice and MultiChoice
331+
- User and Multi user
332+
333+
### Value Field values in `actionInput` :
334+
- Text values:
335+
- a valid string like `"Choice 1"`
336+
- value from other columns : `[$ColumnName]`
337+
- an [expression](./formatting-syntax-reference.md#expressions) like <br>
338+
`"if([$column]> 10, "Choice A", "Choice B")"` <br>
339+
or
340+
`{operator: "+", operands" : ["Choice", "A"]}`
341+
- Number:
342+
- a valid number
343+
- value from other columns : `[$ColumnName]`
344+
- an [expression](./formatting-syntax-reference.md#expressions)
345+
- Date values :
346+
- a date string
347+
- `@now` token
348+
- [expressions](./formatting-syntax-reference.md#expressions) which return a date using builtin date functions
349+
- `addDays` and `addMinutes`, two new functions to support [expressions](./formatting-syntax-reference.md#expressions) like 7 days from today
350+
- Multi-Choice and Multi-Person:
351+
Multi value fields are special, as they need an array value to save multiple values.
352+
- `appendTo` and `removeFrom`, two new functions which operate on multivalue fields.
353+
- `appendTo([$MultiChoiceField], 'MyValue')`
354+
- Person field values:
355+
- User Name or Email
356+
- an [expression](./formatting-syntax-reference.md#expressions) which returns these values
357+
> [!NOTE]
358+
> A query runs with the string value provided on people column and the first person in the returned results is used
359+

docs/declarative-customization/formatting-syntax-reference.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Formatting syntax reference
33
description: Formatting syntax reference
4-
ms.date: 11/11/2021
4+
ms.date: 11/16/2021
55
ms.localizationpriority: high
66
---
77

@@ -180,6 +180,11 @@ An optional property that specifies style attributes to apply to the element spe
180180

181181
'stroke'
182182
'fill-opacity'
183+
184+
'--inline-editor-border-width'
185+
'--inline-editor-border-style'
186+
'--inline-editor-border-radius'
187+
'--inline-editor-border-color'
183188
```
184189

185190
The following example shows the value of a style object. In this example, two style properties (`padding` and `background-color`) will be applied. The `padding` value is a hard-coded string value. The `background-color` value is an Expression that is evaluated to either red (`#ff0000`) or green (`#00ff00`) depending on whether the value of the current field (specified by `@currentField`) is less than 40. For more information, see the Expression object section.
@@ -307,6 +312,21 @@ See [here](./column-formatting.md#formatting-multi-value-fields) for examples.
307312
- **delete**: Clicking the button will open the delete confirmation dialog.
308313
- **editProps**: Clicking the button will open the item properties page in edit mode.
309314
- **openContextMenu**: Clicking the button will open the item's default context menu.
315+
- **setValue**: Clicking the element will update the item with the field values provided.
316+
317+
```JSON
318+
{
319+
"elmType": "div",
320+
"txtContent": "[$FieldName]",
321+
"customRowAction":{
322+
"action": "setValue",
323+
"actionInput": {
324+
"FieldInternalName_1": "FieldValue_1",
325+
"FieldInternalName_2": "FieldValue_2",
326+
}
327+
}
328+
}
329+
```
310330
- **executeFlow**: Clicking the button will launch the specified Flow, specified by ID inside the `actionParams` attribute. For an example of this, see [Create a button to launch a Flow](./formatting-advanced.md#create-a-button-to-launch-a-flow). Below is an example of this type of button.
311331

312332
```JSON
@@ -325,7 +345,6 @@ The `actionParams` attribute can have the following options when using the `exec
325345
- **id**: ID of the Flow to launch _(required)_
326346
- **headerText**: Sets the text at the top of the flow panel _(optional)_
327347
- **runFlowButtonText**: Sets the text of the primary button in the flow panel _(optional)_
328-
-
329348

330349
## customCardProps
331350

@@ -353,6 +372,18 @@ This will be replaced with the referenced column's formatter JSON. Multi level r
353372
}
354373
```
355374

375+
## inlineEditField
376+
377+
Adds the field editor for the referenced column.
378+
379+
```JSON
380+
{
381+
"elmType": "div",
382+
"inlineEditField": "[$FieldName]",
383+
"txtContent": "[$FieldName]"
384+
}
385+
```
386+
356387
## Expressions
357388

358389
Values for `txtContent`, style properties, and attribute properties can be expressed as expressions, so that they are evaluated at runtime based on the context of the current field (or row). Expression objects can be nested to contain other Expression objects.
@@ -473,6 +504,10 @@ Operators specify the type of operation to perform. The following operators are
473504
- padStart
474505
- padEnd
475506
- getUserImage
507+
- addDays
508+
- addMinutes
509+
- appendTo
510+
- removeFrom
476511

477512
**Binary arithmetic operators** - The following are the standard arithmetic binary operators that expect two operands:
478513

@@ -584,6 +619,22 @@ Operators specify the type of operation to perform. The following operators are
584619
- `"src":"=getUserImage('[email protected]', 'large')"` returns a URL pointing to user's profile picture in large resolution
585620
- `"src":"=getUserImage('[email protected]', 'l')"` returns a URL pointing to user's profile picture in large resolution
586621

622+
- **appendTo**: returns an array with the given entry appended to the given array
623+
- `"txtContent": "=appendTo(@currentField, 'Choice 4')"` returns an array with 'Choice 4' added to the @currentField array
624+
- `"txtContent": "=appendTo(@currentField, '[email protected]')"` returns an array with '[email protected]' added to the @currentField array
625+
626+
- **removeFrom**: returns an array with the given entry removed from the given array, if present
627+
- `"txtContent": "=removeFrom(@currentField, 'Choice 4')"` returns an array with 'Choice 4' removed from the @currentField array
628+
- `"txtContent": "=removeFrom(@currentField, '[email protected]')"` returns an array with '[email protected]' removed from the @currentField array
629+
630+
- **addDays**: returns a datetime object with days added (or deducted) from the given datetime value
631+
- `"txtContent": "=addDays(Date('11/14/2021'), 3)"` returns a 11/17/2021, 12:00:00 AM
632+
- `"txtContent": "=addDays(Date('11/14/2021'), -1)"` returns a 11/13/2021, 12:00:00 AM
633+
634+
- **addMinutes**: returns a datetime object with minutes added (or deducted) from the given datetime value
635+
- `"txtContent": "=addMinutes(Date('11/14/2021'), 3)"` returns a 11/14/2021, 12:03:00 AM
636+
- `"txtContent": "=addMinutes(Date('11/14/2021'), -1)"` returns a 11/13/2021, 11:59:00 AM
637+
587638
**Ternary operators** - The following are operators that expect three operands:
588639

589640
- **substring**: returns the part of the string between the start and end indices. - _Only available in SharePoint Online_
Loading

0 commit comments

Comments
 (0)