How to make use of multi-mode jtsage-datebox plugin?
Last Updated :
31 Jul, 2024
In this article, we will learn to use a multi-mode date and time picker plugin for Bootstrap (3&4), jQueryMobile, and Bulma. The jQuery datebox plugin is completely based on JavaScript, HTML, and CSS technologies.
Some key features of the plugin are as follows
- It can limit any condition like date, time, and duration.
- Many callbacks and triggers are available on create, open, close, change, destroy events.
- The tool provides features like slidable columns or weeks.
Please download the required pre-compiled files from the link and save it in your working folder for implementation.
HTML head section of code: The following HTML code snippet holds the head section which has all the common pre-compiled files required for all the following examples to execute.
Note: Please include all the following library links in your codes with proper file paths.
html
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1, maximum-scale=1">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13Fy
QuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script type="text/javascript"
src="../src/js/external/widgetLib.js">
</script>
<script type="text/javascript"
src="../src/js/baseObject.js"></script>
<!-- Enhance JavaScript date object-->
<script type="text/javascript"
src="../src/js/lib/dateEnhance.js"></script>
<!--Date / Time output -->
<script type="text/javascript"
src="../src/js/lib/dateFormatter.js"></script>
<!--Limit functions -->
<script type="text/javascript"
src="../src/js/lib/dateLimit.js"></script>
<!-- Date / Time input -->
<script type="text/javascript"
src="../src/js/lib/dateParser.js"></script>
<!--Event loop -->
<script type="text/javascript"
src="../src/js/lib/eventHandler.js"></script>
<!-- Date adjustments -->
<script type="text/javascript"
src="../src/js/lib/offset.js"></script>
<!-- Public functions -->
<script type="text/javascript"
src="../src/js/lib/public.js"></script>
<!-- Short utility functions -->
<script type="text/javascript"
src="../src/js/lib/shortUtil.js"></script>
<script type="text/javascript"
src="../src/js/lib/standardControls.js"></script>
<!-- Create the widget -->
<script type="text/javascript"
src="../src/js/lib/widgetCreate.js"></script>
<script type="text/javascript"
src="../src/js/lib/widgetOpen.js"></script>
<!-- Closing of the widget -->
<script type="text/javascript"
src="../src/js/lib/widgetClose.js"></script>
<!-- Destroy, Enable & Disable the widget -->
<script type="text/javascript"
src="../src/js/lib/widgetDestroyEnableDisable.js">
</script>
<!-- Handle positioning of the widget -->
<script type="text/javascript"
src="../src/js/lib/positioning.js"></script>
<!-- Twitter Bootstrap v3.4.1 -->
<script type="text/javascript"
src="../src/js/framework/bootstrap.js"></script>
<!-- DateBox, TimeBox, DateTimeBox, DurationBox -->
<script type="text/javascript"
src="../src/js/modes/datebox.js"></script>
<!-- FlipBox, TimeFlipBox, DateTimeFlipBox,
DurationFlipBox -->
<script type="text/javascript"
src="../src/js/modes/flipbox.js"></script>
<!-- CalBox -->
<script type="text/javascript"
src="../src/js/modes/calbox.js"></script>
<!-- SlideBox -->
<script type="text/javascript"
src="../src/js/modes/slidebox.js"></script>
<!-- Used only in the test environment -->
<script type="text/javascript"
src="../src/js/widgetBinding.js"></script>
<!-- Auto enhance for data-role on a page -->
<script type="text/javascript"
src="../src/js/autoInit.js"></script>
<script type="text/javascript"
src="https://cdn.jtsage.com/jtsage-datebox/
i18n/jtsage-datebox.lang.utf8.js">
</script>
</head>
Example 1: The following date and time picker demonstrate for Bootstrap 4. Do not forget to include Bootstrap(3 & 4) pre-compiled files in your Bootstrap codes as shown below.
html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/
4.3.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/
popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/
4.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
jQuery.extend(jQuery.jtsage.datebox.prototype.options, {
mode : "calbox",
/* Display */
displayMode : "inline",
lockInput: false,
displayDropdownPosition : "bottomRight",
useImmediate : true,
useFocus : true,
useButton : true,
/* Callbacks */
beforeOpenCallbackArgs : [ "helloback call", "bye"],
beforeOpenCallback : function(a, b)
{
console.log(a);
console.log(b);
return true;
},
closeCallbackArgs : [ "hi close", "bye close"],
closeCallback : function(a, b)
{
console.log(a);
console.log(b);
},
calDateList : [
["1980-04-25", "JT's Date of Birth"],
["1809-02-12", "Lincoln's Birthday"] ],
calShowDateList : true,
slideDateList : [ ["1980-04-25", "JT's Date of Birth"],
["1809-02-12", "Lincoln's Birthday"] ],
slideShowDateList : true,
minHour : 9,
maxHour : 5,
minTime : "9:00",
maxTime : "17:00",
slideUsePickers : true,
slideYearPickMax : 2020,
slideYearPickMin : 1950,
minuteStep : 15,
/* Control Buttons */
closeTodayButton : true,
useCancelButton : true,
useClearButton : true,
useTodayButton : true,
useCollapsedBut : true,
});
</script>
</head>
<body>
<div class="container" role="main">
<form>
<div class="form-group">
<label class="control-label"for="db">
DateBox</label>
<input class="form-control" name="db"
type="text" data-role="datebox" id="db" />
</div>
</form>
</div>
</body>
</html>
Output:
The following is the output shown in the console to demonstrate the working of callback functions.

Example 2: The following code demonstrates for Bulma. Do not forget to include Bulma pre-compiled files in your Bulma codes as shown below.
html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/
gh/jgthms/[email protected]/css/bulma.css" />
<script type="text/javascript"
src="../src/js/framework/bulma.js"></script>
<script type="text/javascript">
jQuery.extend(jQuery.jtsage.datebox.prototype.options,
{
/* Modes can be changed as per user*/
mode : "slidebox",
/* Display */
displayMode : "dropdown",
/* Linked fields */
linkedField : false,
slideShowDateList : true,
calDateList : [ ["1980-04-25", "JT's Date of Birth"],
["1809-02-12", "Lincoln's Birthday"] ],
calShowDateList : true,
slideDateList : [ ["1980-04-25", "JT's Date of Birth"],
["1809-02-12", "Lincoln's Birthday"] ],
slideShowDateList : true,
calUsePickers : true,
slideUsePickers : true,
calUsePickers : true,
slideUsePickers : true,
useCancelButton : true,
useTodayButton : true,
useCollapsedBut : true,
useCancelButton : true,
useClearButton : true,
useTodayButton : true,
useCollapsedBut : true,
});
</script>
<style>
body{
width:550px;
padding:10px,10px;
}
h3{
margin:0 auto;
padding:20px,20px;
}
</style>
</head>
<body>
<h3>Datebox in Bulma </h3>
<div class="container" role="main">
<form class="form">
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="db">DateBox</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" name="db" type="text"
data-role="datebox" id="db" />
</div>
</div>
</div>
</div>
</form>
</div>
</html>
Output: The following is the output when the mode selected by the developer is "datebox"
The following is the output when the mode selected by the developer is "slidebox".
Note: The developer can try different modes and implement various callback functions and other JavaScript options as per the application's requirement. Only a few options are shown for the demonstration.
Example 3: The following code demonstrates the date and time picker for jQuery mobile codes. Do not forget to include jQuery mobile pre-compiled files in your codes for mobile designs as shown below. Callback functions can be implemented the same as shown in the first example as required.
html
<!DOCTYPE html>
<html lang="en">
<head>
<!-- jQuery mobile libraries -->
<link rel="stylesheet"
href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css" />
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js">
</script>
<script type="text/javascript" src="../src/js/framework/jqm.js"></script>
<!-- jQuery mobile libraries -->
<script type="text/javascript">
jQuery.extend(jQuery.jtsage.datebox.prototype.options, {
/* Mode */
mode : "datebox",
/* Display */
displayMode : "dropdown",
displayDropdownPosition : "bottomMiddle",
linkedField : false,
calDateList : [ ["1980-04-25", "JT's Date of Birth"],
["1809-02-12", "Lincoln's Birthday"] ],
calShowDateList : true,
slideDateList : [ ["1980-04-25", "JT's Date of Birth"],
["1809-02-12", "Lincoln's Birthday"] ],
slideShowDateList : true,
calUsePickers : true,
slideUsePickers : true,
useCancelButton : true,
useClearButton : true,
useTodayButton : true,
});
</script>
</head>
<body>
<div data-role="page" id="main">
<div data-role="header" data-position="fixed">
<h3>DateBox </h3>
</div>
<div class="ui-content" role="main">
<div class="ui-field-contain">
<label for="db">Year Pick</label>
<input name="db" type="text" data-mini="true"
data-role="datebox" id="db" />
</div>
<div id="db-dbAttach"></div>
<div class="ui-field-contain">
<label for="db2">Year Pick</label>
<input name="db2" type="text" data-mini="true"
data-options='{"mode":"datebox", "overrideDateFieldOrder": ["y"],
"overrideHeaderFormat":"%Y", "overrideDateFormat": "%Y" }'
data-role="datebox" id="db2" />
</div>
<div class="ui-field-contain">
<label for="db3">Year Picker - Flipbox</label>
<input name="db3" type="text" data-mini="true"
data-options='{"mode":"flipbox", "overrideDateFieldOrder": ["y"],
"overrideHeaderFormat":"%Y", "overrideDateFormat": "%Y" }'
data-role="datebox" id="db2" />
</div>
</div>
<div data-role="footer" data-position="fixed">
<h1>jQuery Mobile datebox Information</h1>
</div>
</div>
</body>
</html>
Output:
Similar Reads
How to make basic Datepicker using jQuery UI ? In this article, we will be creating a basic Datepicker using jQuery UI. For localization of Datepicker, refer this article. Approach: First, add jQuery UI scripts needed for your project. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"> </script> <script sr
1 min read
How to add date and time picker using only one tag in HTML ? The date picker in HTML is a convenient tool that enhances user experience by allowing users to select a date from a dropdown menu rather than typing it manually. By using the <input> element with the type attribute set to "date", you can generate an interactive date picker in your HTML docume
2 min read
Moment.js Hijri Calendar Plugin In this article, we will learn about moment-hijri, a moment.js plugin. What is moment-hijri? moment-hijri is a Moment.js plugin that allows us to use the moment.js library's utilities and methods with the Hijri calendar, a Muslim and Islamic Lunar calendar. The calendar conversions used by the plug
2 min read
Moment.js Taiwan Calendar Plugin Moment-Taiwan plugin is used to support the Taiwan calendar used in Taiwan and China. It allows seamless integration of Moment.js with the calendar. Calendar Conversions between Gregorian and Taiwan are as follows: Gregorian to Taiwan: year < 1911 : year - 1912 year > 1911 : year - 1911 Taiwan
1 min read
How to Change Date Format in jQuery UI DatePicker ? In this article, we are going to learn about the Datepicker in jQuery. jQuery is the fastest and lightweight JavaScript library that is used to simplify the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. jQuery is widely famous for its m
2 min read
How to set Bootstrap Timepicker using datetimepicker library ? In this article, we will see how we can implement DateTimePicker using a Bootstrap Daterpicker plugin to select a date and time using jQuery. By default, today's date is selected. DateTimePicker has various configurable options which can be used to use DateTimePicker as per the requirements. In this
3 min read
How to create UI Datepicker using jQuery? To implement a jQuery UI Datepicker with localization, configure it to display dates in various languages based on either browser settings or application-specific preferences. Syntax:let userLang = navigator.language || navigator.userLanguage; let options = $.extend({}, // empty object $.datepicker.
2 min read
HTML | <input type="datetime-local"> The HTML <input type="datetime-local"> is used to define a date and time control. The value must include the year, month, day and time. Syntax: <input type="datetime-local"> Example: html <!DOCTYPE html> <html> <head> <title> HTML input type datetime-local </ti
1 min read
jQuery UI Datepicker minDate Option jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Datepicker minDate option is used to set the minimum selectable date. If we set it to null, there is no minimum date. S
1 min read
jQuery UI Datepicker maxDate Option jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Datepicker maxDate option is used to set the maximum selectable date. If we set it to null, there is no maximum date. S
1 min read