DevExtreme Vue - Handle the Value Change Event

To process a new calendar value, you need to handle the value change event. If the handling function is not going to be changed during the lifetime of the widget, assign it to the onValueChanged option when you configure the widget.

jQuery
JavaScript
$(function() {
    $("#calendarContainer").dxCalendar({
        onValueChanged: function (e) {
            var previousValue = e.previousValue;
            var newValue = e.value;
            // Event handling commands go here
        }
    });
});
Angular
HTML
TypeScript
<dx-calendar ...
    [(value)]="calendar_value"
    (onValueChanged)="calendar_valueChanged($event)">
</dx-calendar>
import { DxCalendarModule } from "devextreme-angular";
// ...
export class AppComponent {
    calendar_value: Date = new Date();

    calendar_valueChanged (e) {
        const previousValue = e.previousValue;
        const newValue = e.value;
        // Event handling commands go here
    }
}
@NgModule({
    imports: [
        // ...
        DxCalendarModule
    ],
    // ...
})
Vue
App.vue
<template>
    <DxCalendar
        v-model="calendarValue"
        @value-changed="calendarValueChanged"
    />
</template>

<script>
import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.css';

import DxCalendar from 'devextreme-vue/calendar';

export default {
    components: {
        DxCalendar
    },
    data() {
        calendarValue: new Date()
    },
    methods: {
        calendarValueChanged: function(e) {
            const previousValue = e.previousValue;
            const newValue = e.value;
            // Event handling commands go here
        }
    }
}
</script>
React
App.js
import React from 'react';

import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.css';

import Calendar from 'devextreme-react/calendar';

class App extends React.Component {
    constructor() {
        super();

        this.state = {
            calendarValue: new Date()
        };

        this.calendarValueChanged = this.calendarValueChanged.bind(this);
    }

    render() {
        return (
            <Calendar
                value={this.state.calendarValue}
                onValueChanged={this.calendarValueChanged} />
        );
    }

    calendarValueChanged(e) {
        const previousValue = e.previousValue;
        const newValue = e.value;
        // Event handling commands go here
        this.setState({ value: newValue });
    }
}
export default App;

If you are going to change event handlers at runtime, or if you need to attach several handlers to the value change event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
var valueChangedHandler1 = function (e) {
    var previousValue = e.previousValue;
    var newValue = e.value;
    // First handler of the "valueChanged" event
};

var valueChangedHandler2 = function (e) {
    var previousValue = e.previousValue;
    var newValue = e.value;
    // Second handler of the "valueChanged" event
};

$("#calendarContainer").dxCalendar("instance")
    .on("valueChanged", valueChangedHandler1)
    .on("valueChanged", valueChangedHandler2);
See Also