JavaScript/jQuery DateBox - Synchronize Two DateBoxes

DateBox UI components are often coupled for selecting a date interval. In this case, you need to synchronize the DateBoxes to prevent a user from selecting an interval whose start date is later than the end date. For this, limit one DateBox's range depending on the other's value as shown in the example below.

JavaScript
HTML
  • $(function() {
  • const startDate = $("#startDate").dxDateBox({
  • value: new Date(),
  • onValueChanged: function (e) {
  • endDate.option("min", e.value);
  • }
  • }).dxDateBox("instance");
  • const endDate = $("#endDate").dxDateBox({
  • value: new Date(),
  • onValueChanged: function (e) {
  • startDate.option("max", e.value);
  • }
  • }).dxDateBox("instance");
  • });
  • <div id="startDate"></div>
  • <div id="endDate"></div>

Do not forget to call the getDate() method on the DateBox values when calculating the interval duration.

See Also