{edit:item_id:field_id:required:function:widget_type:widget_properties}

Description

Renders a ready-to-use edit widget (a form input) for ONE field of an existing item, pre-filled with that field current value. The widget matches the field configured input type (text input, checkbox, select, date picker, ...) unless you override it. Resolution: item_id picks the item (leave it empty to edit the field on the CURRENT item being rendered); field_id is the field to edit, given as its full padded id such as headline........ (dots pad the name to 16 characters). edit returns ONLY the widget HTML - it does not output a form tag, a submit button, or any save logic, so it is only useful placed inside a form you build and submit yourself. It returns an empty string when field_id is empty or the item or field cannot be resolved (an unknown item id or field name yields nothing, no error). Companions: editfull renders the same widget WITH its label, live makes the field editable in place (save on change), and ajax edits it through a click-to-edit popup. This command is never cached (the value is read fresh from the database on every render).

Parameters

item_id optional default (current item)

32-character id of the item whose field you want to edit. Leave it empty to edit the field on the item currently being rendered (the surrounding view or page item). An unknown or empty id that cannot be resolved makes the command return an empty string.

field_id required default (none)

The field to edit, given as its full padded id (the field name padded to 16 characters with dots), for example headline........ or switch........... If empty, or if the field does not exist on the item slice, the command returns an empty string.

required optional default 0

Set to 1 to mark the widget as required (it gets the data-aa-required attribute and a required flag, so your form validation can enforce a value). Any other value, or omitted, leaves the field optional.

function optional default (none)

Optional extra behaviour passed through to the widget. For plain edit widgets this is rarely needed; in the live companion it is the JavaScript run after the value is submitted. Leave empty unless a specific widget documents a use for it.

widget_type optional default (field default)

Three-letter code of the widget to render, overriding the field configured input type. For example sel forces a dropdown, chb a checkbox, dte a date picker, txt a plain text input. Omit it to use the widget the field is configured with.

widget_properties optional default (none)

JSON object configuring the chosen widget, for example a list of dropdown options as const_arr. Sample: a JSON object mapping 0 to no and 1 to yes feeds a select widget two options. It may be given as a JSON object or as a JSON string; const_arr supplied as a string is decoded automatically.

Examples

virtual{edit::headline........}
Expected(a text input for the headline field of the item currently being rendered)
Actual
Leave item_id empty to edit the field on the item currently being rendered - handy inside a view that loops over items. The double colon is the empty item_id followed by the field_id.
virtual{edit:ce4ac95c48c3bbe590b80794e47c3e7b:headline........}
Expected(a text input pre-filled with the items headline value, e.g. value="Zeta")
Actual
The everyday form: pass an item id and a padded field id to get that field input widget, pre-filled with the current value. The output is an input element with no surrounding form, so place it inside a form you build and submit yourself. Marked illustrative because the markup carries item-specific ids.
virtual{edit:ce4ac95c48c3bbe590b80794e47c3e7b:switch..........:1}
Expected(a checkbox widget carrying data-aa-required for the switch field)
Actual
The third parameter, required=1, adds the data-aa-required attribute so your form validation can demand a value. Here the switch field renders as its configured checkbox widget.
test[{edit:}]
Expected[]
Actual[]
With no field_id, edit has nothing to render and returns an empty string. The same happens for any field_id that does not exist on the item slice - no error, just nothing.
virtual{edit:ce4ac95c48c3bbe590b80794e47c3e7b:integer.........:::sel:{"const_arr":{"0":"no","1":"yes"}}}
Expected(a select dropdown for the integer field with options no and yes)
Actual
The two empty parameters skip required and function; sel forces a dropdown widget; and the JSON widget_properties supplies its options via const_arr. Use this to present a field with a fixed choice list regardless of how the field is configured.
test[{edit:00000000000000000000000000000000:headline........}]
Expected[]
Actual[]
If item_id cannot be resolved to a real item, edit returns an empty string. Use this to confirm a missing or wrong id fails quietly rather than erroring.