DevExtreme jQuery/JS - Handle the Value Change Event

When a user types a value into the TextBox, this value applies when the change event is raised. If you need the value to be applied on another event, set the valueChangeEvent option.

jQuery
JavaScript
$(function() {
    $("#textBoxContainer").dxTextBox({
        valueChangeEvent: "keyup"
    });
});
Angular
HTML
TypeScript
<dx-text-box
    valueChangeEvent="keyup">
</dx-text-box>
import { DxTextBoxModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxTextBoxModule
    ],
    // ...
})
React
import React from 'react';
import { TextBox } from 'devextreme-react/text-box';

class App extends React.Component {
    render() {
        return (
            <TextBox
                valueChangeEvent="keyup"
            />
        );
    }
}

export default App;

To process a new TextBox 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() {
    $("#textBoxContainer").dxTextBox({
        onValueChanged: function (e) {
            var previousValue = e.previousValue;
            var newValue = e.value;
            // Event handling commands go here
        }
    });
});
Angular
HTML
TypeScript
<dx-text-box
    (onValueChanged)="onValueChanged($event)">
</dx-text-box>
import { DxTextBoxModule } from "devextreme-angular";
// ...
export class AppComponent {
    onValueChanged (e) {
        let previousValue = e.previousValue;
        let newValue = e.value;
        // Event handling commands go here
    }
}
@NgModule({
    imports: [
        // ...
        DxTextBoxModule
    ],
    // ...
})
React
import React from 'react';
import { TextBox } from 'devextreme-react/text-box';

class App extends React.Component {
    render() {
        return (
            <TextBox
                onValueChanged={this.onValueChanged}
            />
        );
    }

    onValueChanged(e) {
        let previousValue = e.previousValue;
        let newValue = e.value;
        // Event handling commands go here
    }
}

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
};

$("#textBoxContainer").dxTextBox("instance")
    .on("valueChanged", valueChangedHandler1)
    .on("valueChanged", valueChangedHandler2);
See Also