Popup Messages and Modal Boxes
Messages are used in the Scheduler to notify a user about an error, confirm or deny an action, choose one of the options and so on. Scheduler messages use the fork of the dhtmlxMessage repository as their basis. So, all the functionality of dhtmlxMessage is actual for dhtmlxScheduler messages.
There are two main types of messages: a simple popup message box and a modal message box with buttons that blocks the work of an application.
A modal message box can belong to one of three possible types:
Basic Popup Message
To create a basic modal message box, use the scheduler.message method. The obligatory parameter of the method is the text of the message:
scheduler.message("The event is updated");
There are three types of message boxes:
- a default message box (type:"info")
- an error message box (type:"error")
- a warning message box (type:"warning")
To create a necessary message box, you need to define the type property with the corresponding value:
// creating an error message box
scheduler.message({
text: "Click on the buttons to explore Scheduler message types",
expire: -1,
type: "error"
});
Different types of popups and modal boxes
To apply different styles to a message box you need to specify a CSS class through the type parameter as described here.
Positioning message boxes
By default, a popup message box appears in the right top corner of the window. It doesn't prevent the work of the parent application, unlike modal message boxes that overlay the parent application and block its work. You can change the position of a message box by using the scheduler.message.position property:
scheduler.message.position = 'bottom';
There are four possible values for the message position:
-
top - displays a message box in the right top corner of the window, set by default
-
bottom - displays a message box in the right bottom corner of the window
-
left - displays a message box on the left side of the window under Scheduler
-
right - displays a message box on the right side of the window under Scheduler
Expire Interval
It's possible to customize the expire interval for a message box with the help of the expire parameter. It is the time period after the end of which the message box disappears (in milliseconds). By default, the expire interval is equal to 4000 milliseconds.
You can either change this value or to cancel the expire period at all, by setting the expire parameter to "-1". In this case a message box will disappear only on a mouse click.
scheduler.message({
type:"error",
text:"Invalid data format",
expire:10000
});
Hiding a Message Box with API
To hide the specified message box manually and not to wait while it hides automatically, you can use the scheduler.message.hide(boxId) method. It takes one parameter:
- boxId - the box id specified in the box's constructor
scheduler.message({
id:"myBox",
text:"Page is loaded"
});
scheduler.message.hide("myBox");
Modal Message Boxes
Modal message boxes prevent the work of the parent app, until a necessary action is performed (usually, button clicking). They close on a button click and a callback function, if any is executed.
There exist three types of modal message boxes:
- Alert Message Box - an alert box with a button;
- Confirm Message Box - a confirmation box with two buttons (to confirm or to cancel);
- Modalbox - a modal message box with an unlimited number of buttons.
Common properties of the boxes are:
- id - the message box's id;
- title - the text of the header;
- type - the type of the message box (a warning or an error);
- text - the text of the message box's body;
- ok - the text of the "OK" button;
- cancel - the text of the "Cancel" button (for the confirm box);
- callback - the function called on button click. Takes true or false as the parameter (subject to the clicked button);
- position - for now supports only one value - "top", any other value will result in center-align;
- width - the width of the modal box (set as CSS <length> or <percentage> values, e.g. "100px", "50%");
- height - the height of the modal box (set as CSS <length> or <percentage> values, e.g. "100px", "50%").