DevExtreme React - Handle the Value Change Event

When a user types a text into the TextArea, the widget writes this text into the value option when the change event is raised. If you need this to happen on another event, set the valueChangeEvent option.

jQuery
JavaScript
$(function() {
    $("#textAreaContainer").dxTextArea({
        valueChangeEvent: "keyup"
    });
});
Angular
HTML
TypeScript
<dx-text-area
    valueChangeEvent="keyup">
</dx-text-area>
import { DxTextAreaModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
     imports: [
         // ...
         DxTextAreaModule
     ],
     // ...
 })
Vue
<template>
    <DxTextArea value-change-event="keyup"/>
</template>

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

import { DxTextArea } from 'devextreme-vue/text-area';

export default {
    components: {
        DxTextArea
    }
}
</script>
React
import React from 'react';
import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.css';

import { TextArea } from 'devextreme-react/text-area';

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

export default App;

To process a new TextArea 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() {
    $("#textAreaContainer").dxTextArea({
        onValueChanged: function (e) {
            const previousValue = e.previousValue;
            const newValue = e.value;
            // Event handling commands go here
        }
    });
});
Angular
HTML
TypeScript
<dx-text-area
    [(value)]="textAreaValue"
    (onValueChanged)="handleValueChange($event)">
</dx-text-area>
import { DxTextAreaModule } from "devextreme-angular";
// ...
export class AppComponent {
    textAreaValue = "The TextArea value";

    handleValueChange(e) {
        const previousValue = e.previousValue;
        const newValue = e.value;
        // Event handling commands go here
    }
}
@NgModule({
     imports: [
         // ...
         DxTextAreaModule
     ],
     // ...
 })
Vue
<template>
    <DxTextArea
        :value.sync="textAreaValue"
        @value-changed="handleValueChange"
    />
</template>

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

import { DxTextArea } from 'devextreme-vue/text-area';

export default {
    components: {
        DxTextArea
    },
    data() {
        return {
            textAreaValue: "The TextArea value"
        };
    },
    methods: {
        handleValueChange(e) {
            const previousValue = e.previousValue;
            const newValue = e.value;
            // Event handling commands go here
        }
    }
}
</script>
React
import React from 'react';
import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.css';

import { TextArea } from 'devextreme-react/text-area';

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

        this.state = {
            textAreaValue: "The TextArea value"
        };

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

    handleValueChange(e) {
        const previousValue = e.previousValue;
        const newValue = e.value;

        this.setState({
            textAreaValue: newValue
        });
    }

    render() {
        return (
            <TextArea
                value={this.state.textAreaValue}
                onValueChanged={this.handleValueChange}
            />
        );
    }
}

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
const valueChangedHandler1 = function (e) {
    const previousValue = e.previousValue;
    const newValue = e.value;
    // First handler of the "valueChanged" event
};

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

$("#textAreaContainer").dxTextArea("instance")
    .on("valueChanged", valueChangedHandler1)
    .on("valueChanged", valueChangedHandler2);
See Also