Skip to main content

onStart

onStart

Called when a form (page) first opens.

Parameters

  • linkArg (dynamic): The argument passed in when navigating to this page from another page. Empty when nothing was passed.

Returns: No return value — this is a callback, so its return value isn't used.

Description

Called when the page loads and its script runs for the first time.
Use it for initialization work: requesting the initial data the page needs, or reflecting a passed-in argument on screen.
Widgets placed in the layout can be referenced anywhere in a script by the name (layer ID) you gave them in Studio.
Register the function to run when a widget fires an event as widgetName.onXxx = (arg) => { ... }. You must do this registration inside onStart.

Example

function onStart(linkArg) {
$log.i("page started, linkArg=" + linkArg);

// Register widget event handlers in onStart
btnRefresh.onTap = () => {
$vm.requestData("mainList");
};

icoBack.onTap = () => {
$act.navigatorPop();
};

if (linkArg) {
$vm.setDSValue("uiState.selectedId", linkArg);
}
}

Related and cautions

  • When a page becomes active again — returning to it with the back gesture, for example — onStart is not called again; onActivate/onActive runs instead. onStart fires exactly once, when the page loads completely fresh.
  • Registering widget event handlers in onStart is the standard practice.