Line 19: Line 19:
 
'''template ''' = This argument has been kept to keep editing a template wiki page and editing a JSON page similar to each other.
 
'''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.  
 
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.
+
 
 +
*'''json''' : When you create a JSON page with _create, every new named array will also get a unique id, called '''ffID'''. The following example tells 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:
 
Example JSON:
Line 57: Line 58:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
This will change the first Color array value into the value of the form field 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
 
'''formfield''' = Name of the key in the JSON. When using template type json, then the formfield in the form should have the same name
  

Revision as of 21:23, 2 January 2023

Name

_edit JSON content

Type

_edit

Synopsis

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 tells 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 using the JSONPath (xpath for JSON). You tell FlexForm exactly what part of the JSON you want to edit and what value of a form input field to use. You can use the full root path method ( $. ) or leave it out for convenience and FlexForm will add it automatically. 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).

Links

https://www.mediawiki.org/wiki/Multi-Content_Revisions

https://github.com/Galbar/JsonPath-PHP