Skip to content

Commit 55a222c

Browse files
committed
Support edit actions
1 parent 29d4c10 commit 55a222c

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

docs/declarative-customization/formatting-advanced.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,105 @@ The following image shows a list with a Gallery layout referencing the Category
242242
}
243243
}
244244
```
245+
## Inline Editing
246+
247+
With inline editing, formatters have the ability to load field editors to edit field data on an item.
248+
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.
249+
250+
A special json property `inlineEditField` is used with value as the field internal name __`[$FieldName]`__ at the target element in the json.
251+
252+
```json
253+
{
254+
"elmType": "div",
255+
"inlineEditField": "[$FieldName]",
256+
"txtContent": "[$FieldName]"
257+
}
258+
```
259+
260+
<img src="../images/sp-columnformatting-inline-editing.gif" alt="Inline Editing using inlineEditField property"/>
261+
262+
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.
263+
264+
### Supported Field Types
265+
List of supported field types for inline editing
266+
- Single line text
267+
- Multi line text (without RTF)
268+
- Number
269+
- DateTime
270+
- Choice and MultiChoice
271+
- User and Multi user
272+
- Lookup
273+
274+
### Hover Borders and Customizations
275+
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`.
276+
277+
```json
278+
{
279+
"elmType": "div",
280+
"inlineEditField": "[$FieldName]",
281+
"txtContent": "[$FieldName]",
282+
"style": {
283+
"--inline-editor-border-color": "transparent transparent red transparent",
284+
"border-color": "gray",
285+
"border-width": "1px",
286+
"border-style": "solid"
287+
}
288+
}
289+
```
290+
291+
## Set multiple field values of an Item using customRowAction
292+
293+
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.
294+
295+
The below JSON will set value of `FieldInternalName_1`, `FieldInternalName_2` and `FieldInternalName_3`with the values provided.
296+
297+
```json
298+
{
299+
"elmType": "div",
300+
"txtContent": "[$FieldName]",
301+
"customRowAction":{
302+
"action": "setValue",
303+
"actionInput": {
304+
"FieldInternalName_1": "FieldValue_1",
305+
"FieldInternalName_2": "FieldValue_2",
306+
"FieldInternalName_3": "=if([$Status] == 'Completed', 'yes', 'no')"
307+
}
308+
}
309+
}
310+
```
311+
312+
### Supported Field Types
313+
- Single line text
314+
- Multi line text (without RTF)
315+
- Number
316+
- DateTime
317+
- Choice and MultiChoice
318+
- User and Multi user
319+
320+
### Value Field values in `actionInput` :
321+
- Text values:
322+
- a valid string like `"Choice 1"`
323+
- value from other columns : `[$ColumnName]`
324+
- an [expression](./formatting-syntax-reference#expressions) like <br>
325+
`"if([$column]> 10, "Choice A", "Choice B")"` <br>
326+
or
327+
`{operator: "+", operands" : ["Choice", "A"]}`
328+
- Number:
329+
- a valid number
330+
- value from other columns : `[$ColumnName]`
331+
- an [expression](./formatting-syntax-reference#expressions)
332+
- Date values :
333+
- a date string
334+
- `@now` token
335+
- [expressions](./formatting-syntax-reference#expressions) which return a date using builtin date functions
336+
- `addDays` and `addMinutes`, two new functions to support [expressions](./formatting-syntax-reference#expressions) like 7 days from today
337+
- Multi-Choice and Multi-Person:
338+
Multi value fields are special, as they need an array value to save multiple values.
339+
- `appendTo` and `removeFrom`, two new functions which operate on multivalue fields.
340+
- `appendTo([$MultiChoiceField], 'MyValue')`
341+
- Person field values:
342+
- User Name or Email
343+
- an [expression](./formatting-syntax-reference#expressions) which returns these values
344+
> [!NOTE]
345+
> A query runs with the string value provided on people column and the first person in the returned results is used
346+

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -325,7 +330,22 @@ The `actionParams` attribute can have the following options when using the `exec
325330
- **id**: ID of the Flow to launch _(required)_
326331
- **headerText**: Sets the text at the top of the flow panel _(optional)_
327332
- **runFlowButtonText**: Sets the text of the primary button in the flow panel _(optional)_
328-
-
333+
334+
- **setValue**: Clicking the element will update the item with the field values provided.
335+
336+
```JSON
337+
{
338+
"elmType": "div",
339+
"txtContent": "[$FieldName]",
340+
"customRowAction":{
341+
"action": "setValue",
342+
"actionInput": {
343+
"FieldInternalName_1": "FieldValue_1",
344+
"FieldInternalName_2": "FieldValue_2",
345+
}
346+
}
347+
}
348+
```
329349

330350
## customCardProps
331351

@@ -353,6 +373,18 @@ This will be replaced with the referenced column's formatter JSON. Multi level r
353373
}
354374
```
355375

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

358390
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 +505,10 @@ Operators specify the type of operation to perform. The following operators are
473505
- padStart
474506
- padEnd
475507
- getUserImage
508+
- addDays
509+
- addMinutes
510+
- appendTo
511+
- removeFrom
476512

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

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

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

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

0 commit comments

Comments
 (0)