wf-action-modal.js
extends the modal system for server-driven AJAX workflows. Add
data-wf-action
to any button – no per-page JS setup needed. The module registers a single delegated click listener on the document and handles the full lifecycle: fetch form fragment → render modal → POST → toast feedback → DOM mutation.
How it Works - Copy
On click the module GETs an HTML fragment from
data-wf-url
and renders it inside a modal. On confirmation, it POSTs the same URL, reads the JSON response, shows a toast, then mutates the DOM using the
data-wf-complete
strategy.
GETs a confirmation fragment (warning message), then on confirmation POSTs the action and removes the target element from the DOM via
data-wf-complete="remove"
.
This message will be removed from the DOM on successful delete.
Loads a checkbox form. On submit shows a toast with the saved permissions – no DOM element is mutated since the trigger omits
data-wf-parent
and
data-wf-complete
.
Opens a compose form. Submitting with empty fields returns validation errors rendered as a structured message list inside the modal. Fill in both fields to see a success toast.
data-wf-confirm
skips the GET entirely and renders a client-side confirmation body immediately. Use it for trash, restore, archive, and permanent delete. Add
data-wf-confirm-text
to override the default message for destructive actions.
Blog post #1published
Blog post #2archived
Legacy articlepublished
HTML
<!-- Trash (default confirm text) -->
<button type="button" data-wf-action data-wf-confirm
data-wf-url="/api/api-action-modal.php"
data-wf-params='{"action":"trash","id":5}'
data-wf-title="Move to trash?"
data-wf-label="Move to trash"
data-wf-parent="#item-5"
data-wf-complete="remove"
class="wf-btn ...">
Trash
</button>
<!-- Delete (custom warning text) -->
<button type="button" data-wf-action data-wf-confirm
data-wf-confirm-text="This will permanently erase the record. There is no undo."
data-wf-url="/api/api-action-modal.php"
data-wf-params='{"action":"delete","id":5}'
data-wf-title="Delete permanently?"
data-wf-label="Delete"
data-wf-parent="#item-5"
data-wf-complete="remove"
class="wf-btn ...">
Delete
</button>
Trigger Attributes
Attribute
Default
Description
data-wf-action
-
Required. Marks the element as an action-modal trigger. No value needed.
data-wf-url="/path"
-
Endpoint for GET (load fragment) and POST (submit). Same URL for both.
data-wf-params='{"k":"v"}'
-
JSON object merged into the GET query string and the POST body.
data-wf-title="Title"
data-wf-label
Modal header title. Falls back to
data-wf-label
then "Action".
data-wf-label="Save"
"OK"
OK / submit button label.
data-wf-cancel="Cancel"
"Cancel"
Cancel button label.
data-wf-modal-size="sm"
"sm"
Panel width preset:
sm
,
md
,
lg
,
xl
,
full
.
data-wf-parent="#selector"
-
CSS selector for the DOM element to mutate after a successful POST.