WebFormController

What a 4D function returns to act on the page. It is serialised into the response and replayed client-side, so everything it carries happens after your function ends.

Function myAction($vo_POST : Object)->$vo_WebResponse : cs.bspkComponent.WebFormController
    $vo_WebResponse:=cs.bspkComponent.WebFormController.new()
    $vo_WebResponse.sendAlert("success"; BSPK_Translate("Toast_saved"))
    $vo_WebResponse.reloadBlock("myList")

The methods

MethodNotes
sendAlert(type; title; message; duration)Types: success, error, warning, info
sendAlertAfterRedirect(…)Survives a reload: use it when you redirect
reloadBlock(nameOrUuid; options)One block per call, no collection. Call it again for another
redirectToRoute(menuName; lang; params; optionalParams)Routes by menu name, not by URL
reloadBlocksWithConditionalDisplay($vo_POST)Re-evaluates conditional blocks

Trap: sendAlert followed by a redirect destroys the toast: the page reloads before it can be read. If the message carries information, and especially if it is the only explanation of why the page just reloaded, use sendAlertAfterRedirect.

Raw actions

Anything without a dedicated method is pushed onto vc_Action:

$vo_WebResponse.vc_Action.push({vt_Action: "showModal"; vt_BlockName: "myModal"})
$vo_WebResponse.vc_Action.push({vt_Action: "closeModal"; vt_BlockName: "myModal"})

vt_modalId expects a UUID, vt_BlockName expects a name

On the client side, the closeModal handler in bspk.js resolves vt_modalId as an HTML id, then as bspk[data-uuid="…"], so it wants a uuid. Passing a block name there closes nothing, silently: the modal stays open, no error. Only the other branch, on vt_BlockName, accepts a name.

// WRONG - modal stays open, no error
$vo_WebResponse.vc_Action.push({vt_Action: "closeModal"; vt_modalId: "myModalBlocName"})
// RIGHT
$vo_WebResponse.vc_Action.push({vt_Action: "closeModal"; vt_BlockName: "myModalBlocName"})

And mind the asymmetry with events: a render function takes vo_Params.vt_BlocName, while a server-side action takes vt_BlockName.

A modal has no native title

vt_Title exists in some older modals' properties, but no template renders it. Put the title in a text block at the top of the modal's content. The properties that are rendered: vb_closeCross, vb_closeClickOutside, vb_PanelMode, vt_Position, vt_Id.

Filling a modal before showing it

BSPK_SET_PROCESS_VAR("vo_SelectedItemData"; {fullName: "John"; amount: 100})
$vo_WebResponse.reloadBlock("myModal")
$vo_WebResponse.vc_Action.push({vt_Action: "showModal"; vt_BlockName: "myModal"})

Set the data, reload the block so it re-renders with it, then show it. Showing first displays the previous content.

See also