{ajax:item_id:field_id:show_alias:onsuccess:widget_type:widget_properties}

Description

Renders a field value as a clickable control that visitors with edit rights can change in place - clicking it opens a small inline editor that saves over AJAX, with no page reload. Give it the item id and the field id; the field id is the only required parameter and without it ajax outputs nothing. Leave the item id empty to edit the field on the current item (the alias _#ITEM_ID_ in a view or template). The read-only display, before anyone clicks, is the field value formatted for humans; pass a third parameter to supply your own display template, and put the alias _#AA_AJAX_ inside it to attach the click-to-edit handler to one element instead of the whole block. The fourth parameter is JavaScript run after a successful save, for example AA_Refresh(this) to reload the surrounding block. The last two parameters (widget type and widget properties) choose a specific editing widget but are still being wired up. To turn editing off and print only the value - the read-only fallback, also used when a visitor cannot edit - set the constant AA_FLAG_NOEDIT to 1. An empty field value shows as two dashes.

Parameters

item_id optional default empty = the current item

Id of the item whose field you want to edit. Leave empty to use the current item being rendered - the usual case in a view or template, written as item_id set to the alias for the current item id.

field_id required

The field to edit, given by its field id (for example headline........ or category........). This is the only required parameter; without it ajax outputs nothing.

show_alias optional default the field value, formatted for humans

Display template for the read-only state - what the visitor sees before clicking. Plain text is shown verbatim; reference the field with its alias to show the stored value. Put the alias _#AA_AJAX_ somewhere in this template to attach the click-to-edit handler to that spot instead of the whole block.

onsuccess optional default empty (no callback)

JavaScript run after a successful save. AA_Refresh(this) reloads the nearest enclosing block; AA_Refresh('elementId') reloads a named element. Use it to update other parts of the page that depend on the changed value.

widget_type optional default empty (the field's configured widget)

Three-letter code of the input widget to use for editing (for example sel for a select box), overriding the field's configured widget. Editing widget support is still being wired up; leave empty to use the field's own widget.

widget_properties optional default empty

JSON configuration for the chosen widget, for example a const_arr of value-to-label pairs for a select. Paired with widget_type. Editing widget support is still being wired up.

Examples

virtual{ajax:a65d19971986e750761f0efcd9a16b1b:headline........}
Expected(Alpha, shown as a clickable inline-edit control)
Actual
Alpha
The everyday form: item id, field id. AA shows the field value as a clickable control; clicking it opens an inline editor that saves over AJAX. In real templates use the current item via _#ITEM_ID_, as in {ajax:_#ITEM_ID_:headline........}. The rendered output is live HTML, so this example is illustrative, not asserted.
test{define:AA_FLAG_NOEDIT:1}{ajax:a65d19971986e750761f0efcd9a16b1b:headline........}{define:AA_FLAG_NOEDIT:0}
ExpectedAlpha
ActualAlpha
With the constant AA_FLAG_NOEDIT set to 1, ajax drops the editor and prints just the field value - the read-only fallback. Here the headline field of the fixture item holds Alpha. Defining and clearing the flag in the same expression keeps the example self-contained.
test{define:AA_FLAG_NOEDIT:1}{ajax:a65d19971986e750761f0efcd9a16b1b:integer.........}{define:AA_FLAG_NOEDIT:0}
Expected14
Actual14
Any field works, not only text. The number field of the fixture item holds 14. ajax renders whatever the field stores; the inline editor (when editing is on) picks an input suited to the field type.
test{define:AA_FLAG_NOEDIT:1}{ajax:a65d19971986e750761f0efcd9a16b1b:edit_note.......}{define:AA_FLAG_NOEDIT:0}
Expected--
Actual--
When the field is empty, ajax shows a two-dash placeholder (--) so there is still something to click. The fixture item leaves its editor-note field blank, so the value renders as --.
test{define:AA_FLAG_NOEDIT:1}{ajax:a65d19971986e750761f0efcd9a16b1b:integer.........:edit me}{define:AA_FLAG_NOEDIT:0}
Expectededit me
Actualedit me
The third parameter (show_alias) is the DISPLAY template, not just a label - whatever you pass is rendered in place of the value. Plain text like edit me shows verbatim; to show the value too, reference the field with its alias inside this template. Use it to label the editable spot.
virtual{ajax:a65d19971986e750761f0efcd9a16b1b:file............:<span>change file</span>:AA_Refresh(this)}
Expected(clickable 'change file' control; runs AA_Refresh(this) after saving)
Actual
change file
The fourth parameter (onsuccess) is JavaScript run after a successful save - here AA_Refresh(this) reloads the nearest enclosing block so the page reflects the new value without a full reload. Use AA_Refresh('elementId') to refresh a specific element. Live HTML, so illustrative.
virtual{ajax:a65d19971986e750761f0efcd9a16b1b:headline........:Edit _#AA_AJAX_ inline}
Expected(your markup, with the click-to-edit handler attached where _#AA_AJAX_ appears)
Actual
Edit onclick="displayInput('ajaxv_aa-ua65d19971986e750761f0efcd9a16b1b-headline________', 'a65d19971986e750761f0efcd9a16b1b', 'headline........', '', '', 'CpYM3ToWF33NXrMCxhrKMhlfixZoGZON9XgH8WFxpEVrrgIrZW806UhQjHeQs6Aw')" inline
By default the whole rendered block is the click target. Put the _#AA_AJAX_ alias in your show_alias to move the click handler onto a specific element instead, for example wrapping it on a button so only the button opens the editor. Live HTML, so illustrative.