Webix UI library helps the app communicate with users with the help of messages that can warn about error, log events, display variable values, etc.
An info message is non-modal. It is displayed in the top right corner of the window and doesn't prevent the work of the parent app as modal message boxes do.
A basic message is created with the help of the webix.message() function that takes a message text as a parameter (in the short form).
webix.message("All is correct");
You can also use an extended form to initialize a message. It contains an object with the parameters listed below:
// extended initialization
webix.message({
text:"Form data are Invalid",
type:"error",
expire: 10000,
id:"message1"
});
Message boxes can be of the following types:
The "info" type is set by default, while the "error", "success" and "debug" types are defined through the extended form of initialization:
webix.message({type:"error", text:"Form data are Invalid"});
Message | Image |
---|---|
Default (type:"info") | |
Error (type:"error") | |
Debug (type:"debug") | |
Success (type:"success") |
Related sample: Validation with a Complex Rule
By default, Webix Message disappears either on mouse clicking somewhere on its area, or in 4000 milliseconds after appearing.
To change the expire interval or cancel it, use the expire parameter:
webix.message({
type:"error",
text:"Form data are Invalid",
expire:10000
// expire:-1 for canceling the expire period
})
If you cancel the expire period, such a message will disappear only on a mouse click.
Message boxes can also be hidden using API:
var message = webix.message("Hi!");
webix.message.hide(message);
// or via the message id
webix.message("Hi!","info",-1,"hi");
webix.message.hide("hi");
You can redefine the style of any message box through CSS. The name of a CSS class corresponding to a particular type of a message box is kept as webix_[type]. You can specify your own styling for a message box itself, as well as for its inner and outer borders:
/* message box + inner border */
.webix_mystyle div{
background-color:#cdb4e4;
border: 1px solid #676d71;
color:#484444
}
/* outer border */
.webix_mystyle {
background-color: #7e59bd;
border: 1px solid #7e59bd;
box-shadow: 0 0 10px #000
}
To apply the redefined style to the message box, specify its name in the box configuration using the type property:
webix.message({
type:"mystyle",
text:"Some message"
});
webix.message provides the following global settings that are applied to all message instances:
webix.message.expire = 2000; // messages expire in 2 seconds
// messages appear in the right bottom corner
webix.message.position = "bottom";
Related sample: Message: Global Settings
The position setting takes the following values:
If you want to specify custom horizontal or vertical position use CSS.
Modal message boxes resemble UI-related modal Window. They do not prevent the workflow on the parent app. However they add a modal overlay over the UI, which stays there until the user clicks a button in the box or the box is hidden with hide API.
Message boxes contain some text and buttons ("OK", "Cancel", etc).
There are four types of modal message boxes:
The boxes share some common properties, namely:
Please note that created boxes don't prevent the workflow on the application parent window.
The text of the button of an alert box is defined as the value of the ok parameter.
Short form
webix.alert("Test alert");
Extended form
webix.alert({
title:"Custom title",
ok:"Custom text",
text:"Warning"
});
webix.alert() returns a promise that is resolved when a user clicks the button. The then() receives the alert result status (true).
webix.alert({
title:"Custom title",
ok:"Custom text",
text:"Result: yes",
type:"alert-warning"
}).then(function(result){
// some action when the alert window is closed
});
confirm message boxes have two buttons: "OK" and "Cancel".
Short form
webix.confirm("Test confirm");
The text on the buttons can be changed with the same-name properties.
Extended form
webix.confirm({
title:"Custom title",
ok:"Yes",
cancel:"No",
text:"Test confirm"
});
Related sample: Confirm Message
webix.confirm() returns a promise.
webix.confirm("Test confirm").then(function(result){
webix.message("OK");
}).fail(function(){
webix.message("Cancel");
});
Webix modalbox resembles alert and confirm boxes, but with some differences:
webix.modalbox({
title:"Custom title",
buttons:["Yes", "No", "Maybe"],
text:"Any html content here",
width:500
});
Modalboxes can be initialized in two forms: the short and the extended forms.
The short form:
webix.modalbox("Custom title","alert-error");
The extended form:
webix.modalbox({
title:"Title",
buttons:["Yes", "No", "Maybe"],
text:"Some text",
width:500
});
webix.modalbox() returns a promise. The promise resolves if the user clicks a button. For handling these actions, use the then() method that receives the result status (index of a button).
webix.modalbox({
title:"Question",
buttons:["Yes", "No", "Maybe"],
text:"Do you love JS?",
width:500
}).then(function(result){
switch(result){
case "0":
webix.message("Good!");
break;
case "1":
webix.message("Why?..");
break;
case "2":
webix.message("Come back later");
}
}
);
In addition to the common config shared with the alert and confirm message boxes, Webix prompt has an optional input property. It's an object that contains the following fields:
webix.prompt({
title: "What is your favourite cat breed?",
text: "Share with us below",
ok: "Submit",
cancel: "Cancel",
input: {
required:true,
placeholder:"Siamese, Maine Coon, Sphynx...",
}
});
webix.prompt() returns a promise that follows the common rules:
webix.prompt({
title: "What is your favourite cat breed?",
text: "Share with us below",
ok: "Submit",
cancel: "Cancel",
input: {
required:true,
placeholder:"Siamese, Maine Coon, Sphynx...",
},
width:350,
}).then(function(result){
webix.alert({
text: "Ooh, " + result + " cats are so cute!"
});
}).fail(function(){
webix.alert({
type: "alert-error",
text: "Cancelled"
});
});
You can initialize a modal box inside a container. The box will be positioned in the center of the container, and the modal overlay will cover only the container:
webix.ui({
view:"window",
id:"window1",
width:600, height:400,
head:"Window",
body:"Container for the confirm box"
}).show();
webix.confirm({
title:"Confirm",
text:"Any html content here",
container:$$("window1").$view
});
Related sample: Modalbox: Container
There are 2 subtypes of each modal box for showing a warning or an error.
webix.alert({
title: "Close",
text: "You can't close this window!",
type:"alert-warning"
});
webix.alert({
title: "Close",
text: "You can't close this window!",
type:"alert-error"
});
webix.confirm({
title: "Close",
text: "You can't close this window!",
type:"confirm-warning"
});
webix.confirm({
title: "Close",
text: "You can't close this window!",
type:"confirm-error"
});
The modal message box may use the same types that are applied to alert message boxes. For example:
webix.modalbox({
title: "Close",
text: "You can't close this window!",
buttons:["Yes","No","Maybe"],
width:500,
type:"alert-warning"
});
Webix prompt can use the same types as alert message box does:
webix.prompt({
title: "What is your favourite cat breed?",
text: "Share with us below",
type: "prompt-error"
});
Alert, confirm and modal boxes are closed when the a user clicks the button. You can also close an alert box using the modalbox API:
For these needs you should define the id for a modal box to pass it to the .hide() method afterwards:
webix.alert({ title:"Test alert", type:"alert-warning", id:"1" });
webix.modalbox.hide("1");
Additionally, you can hide all modal boxes by:
webix.modalbox.hideAll();
Keyboard functionality for modal boxes is controlled by the webix.message.keyboard property that is initially set to true.
By default, modal boxes block keyboard events of the page. Users can use only the following keys that set a modal box value and close it:
To disable the above mentioned keys and enable standard keyboard events, you should set the keyboard property to false:
webix.message.keyboard = false;
webix.modalbox({/* ... */})
From now on, the user gets a possibility to use full keyboard, for instance, for typing values into inputs inside modal boxes.
Back to top