m (Charlot moved page DevOps:Doc/FlexForm/2.0/json to json without leaving a redirect) |
|||
ws-class-props | |||
---|---|---|---|
Line 5: | Line 5: | ||
|Doc sort order=10 | |Doc sort order=10 | ||
|Doc target group=User | |Doc target group=User | ||
+ | |Doc synopsis=Edit JSON content | ||
}} | }} |
Revision as of 21:56, 11 December 2022
Name
_edit JSON content
Type
_edit
Synopsis
Introduced in FlexForm version 1.1.43. Using a form to edit pages that have content with JSON.
Description
How to edit JSON content pages in the wiki with FlexForm.
The edit function is very similar to editing template content, we will brake down the differences here.
Parameters
_edit
target = Target page ( title or page id ) that needs to be edited
mwformat = "json". Tell an edit that we are working with JSON
template = This argument has been kept to keep editing a template wiki page and editing a JSON page similar to each other. Name of the template differs from editing template content and now has two options : json and jsonk.
- json : When you create a JSON page with _create, every new named array will also get a unique id, called ffID. The following example tell FlexForm to find a certain ffID and then find a named value ( so the key ) called Title. FlexForm will then check if the submitted form has an input with the same name the "Title" and use it's value to add to the JSON.
Example JSON:
{
"Coats": {
"ffID": 1669192355,
"Title": "The Body protector",
"Type": "Bodywarmer",
"Color": [
"blue",
"pink"
]
}
}
Example EDIT:
<_edit target="Json_test_result" format="json" template="json|ffID=1669192355" formfield="Title" />
If you do not have a ffID, but do have something else in the JSON that is always unique you can use those instead of a ffID. For example, if you know the Type:"Bodywamer" is unique in this JSON, you can edit the Title of the JSON this way :
<_edit target="Json_test_result" format="json" template="json|Type=Bodywarmer" formfield="Title" />
- jsonk : This option lets you traverse down a JSON manually. You tell FlexForm exactly what part of the JSON you want to edit and what value of a form input field to use. The following example uses the same JSON example from above and we tell FlexForm to go to Coats->Title, then take the form input of type Title and put that value in the JSON.
<_edit target="Json_test_result" format="json" template="jsonk|Coats.Title" formfield="Title" />
You can also use a different input in your form to use as the new value
<_edit target="Json_test_result" format="json" template="jsonk|Coats.Title" formfield="Alternative title" />
You can even traverse into unnamed values like so :
<_edit target="Json_test_result" format="json" template="jsonk|Coats.Color.0" formfield="Title" />
This will change the first Color array value into the value of the form field Title. formfield = Name of the key in the JSON. When using template type json, then the formfield in the form should have the same name
value = [optional] Don't read the value from the form field, but use this value explicitly
mwslot = [optional] Name of content slot to use. Defaults to main content slot
Note
- You can have multiple _edit's in a form all doing different tasks.
- If you omit value, then the value of the form will be used (so what a user has filled in).