Vue NumberBox - Handle the Value Change Event
By default, the value of the NumberBox is changed when the change event is raised. If you need the value to be changed on another event, set the valueChangeEvent property.
jQuery
$(function() { $("#numberBoxContainer").dxNumberBox({ value: 20, valueChangeEvent: "keyup" }); });
Angular
<dx-number-box [value]="20" valueChangeEvent="keyup"> </dx-number-box>
import { DxNumberBoxModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxNumberBoxModule ], // ... })
Vue
<template> <DxNumberBox :value="20" value-change-event="keyup" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxNumberBox from 'devextreme-vue/number-box'; export default { components: { DxNumberBox } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import NumberBox from 'devextreme-react/number-box'; class App extends React.Component { render() { return ( <NumberBox defaultValue={20} valueChangeEvent="keyup" /> ); } } export default App;
To process a new NumberBox value, you need to handle the value change event. If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onValueChanged property when you configure the UI component.
jQuery
$(function() { $("#numberBoxContainer").dxNumberBox({ onValueChanged: function (e) { const previousValue = e.previousValue; const newValue = e.value; // Event handling commands go here } }); });
Angular
<dx-number-box ... [(value)]="numberBox_value" (onValueChanged)="numberBox_valueChanged($event)"> </dx-number-box>
import { DxNumberBoxModule } from "devextreme-angular"; // ... export class AppComponent { numberBox_value: number = 10; numberBox_valueChanged (e) { const previousValue = e.previousValue; const newValue = e.value; // Event handling commands go here } } @NgModule({ imports: [ // ... DxNumberBoxModule ], // ... })
Vue
<template> <DxNumberBox v-bind="numberBoxValue" @value-changed="numberBoxValueChanged" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxNumberBox from 'devextreme-vue/number-box'; export default { components: { DxNumberBox }, data() { numberBoxValue: 10 }, methods: { numberBoxValueChanged(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.light.css'; import NumberBox from 'devextreme-react/number-box'; class App extends React.Component { constructor() { super(); this.state = { numberBoxValue: 10 }; this.numberBoxValueChanged.bind(this); } render() { return ( <NumberBox value={this.numberBoxValue} onValueChanged={this.numberBoxValueChanged} /> ); } numberBoxValueChanged(e) { const previousValue = e.previousValue; const newValue = e.value; // Event handling commands go here this.setState({ numberBoxValue: 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.
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 }; $("#numberBoxContainer").dxNumberBox("instance") .on("valueChanged", valueChangedHandler1) .on("valueChanged", valueChangedHandler2);
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.