DevExtreme jQuery - Synchronize Two DateBoxes

DateBox widgets 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.

jQuery
JavaScript
HTML
$(function() {
    var startDate = $("#startDate").dxDateBox({
        value: new Date(),
        onValueChanged: function (e) {
            endDate.option("min", e.value);
        }
    }).dxDateBox("instance");
    var endDate = $("#endDate").dxDateBox({
        value: new Date(),
        onValueChanged: function (e) {
            startDate.option("max", e.value);
        }
    }).dxDateBox("instance");
});
<div id="startDate"></div>
<div id="endDate"></div>
Angular
HTML
TypeScript
<dx-date-box 
    [(max)]="endValue"
    [(value)]="startValue">
</dx-date-box>
<dx-date-box 
    [(min)]="startValue"
    [(value)]="endValue">
</dx-date-box>
import { DxDateBoxModule } from "devextreme-angular";
// ...
export class AppComponent {
    startValue: Date = new Date();
    endValue: Date = new Date();
}
@NgModule({
    imports: [
        // ...
        DxDateBoxModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div dx-date-box="{
    bindingOptions: {
        max: 'endValue'
        value: 'startValue'
    }
}"></div>
<div dx-date-box="{
    bindingOptions: {
        min: 'startValue'
        value: 'endValue'
    }
}"></div>
function Controller($scope) {
    $scope.startValue = new Date();
    $scope.endValue = new Date();
}
Knockout
HTML
JavaScript
<div data-bind="dxDateBox: {
    max: endValue
    value: startValue
}"></div>
<div data-bind="dxDateBox: {
    min: startValue
    value: endValue
}"></div>
var viewModel = {
    startDate: ko.observable(new Date()),
    endDate: ko.observable(new Date()),
};
ko.applyBindings(viewModel);

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

See Also