← API Index · How to use components
flash component #oo-flash
This component shows info and error messages from previous or current actions.
Messages are issued by the system (e.g. "added to cart", logon errors) and displayed either immediately or — if a page change follows the action — on the next page at initialisation time. A message is shown only once. Info messages fade out after a while, error messages stay until the user clicks on them.
Every page that hosts components should host a flash component too, otherwise messages get lost (they are logged to the console instead).
How components are mounted, how switch values are resolved and how debug output is enabled is described in the use-js-components skill.
<div id="oo-flash" data-oo-cart-page="cart.html"></div>
component switches
| Switch | Default | Description |
|---|---|---|
oo-cart-page |
– | Page hosting the cart component. Cart related messages ("added to cart") contain a link that leads there. |
oo-flash-to |
5000 |
Milliseconds an info message stays on screen before it fades out. Error messages don't fade out. |
Issuing messages from your own script
The same functions the components use are available to your script via oo.ui:
| Function | Description |
|---|---|
oo.ui.addFlash(msg) |
Collects an info message, to be displayed at the next opportunity (placeFlash() or the next page initialisation). |
oo.ui.addFlashError(msg) |
Same for an error message. |
oo.ui.placeFlash() |
Shows all collected messages now. |
oo.ui.showFlash(msg) / oo.ui.showFlashError(msg) |
Adds and shows immediately. |
oo.ui.clearFlash() |
Drops all collected messages. |
oor.require(["oo"], function (oo) {
function appInit() {
oo.ui.addFlash("Hello Flash Gordon");
oo.ui.placeFlash();
window.setTimeout(function () {
oo.ui.showFlashError("Beware! The Fire Dragon!");
}, 5000);
}
oo.initWeb(appInit, false, shopid);
});
Messages may contain HTML. Normally none of this is needed — the component is driven by the other components automatically.
debug options
Debug scope flash (enable with data-oo-debug="true" on the element or debug:flash:all+, see the skill):
| Term | Description |
|---|---|
flash:all |
Every message shown, with the page it was shown on. |