Handle the Value Change Event
To process new TagBox values, 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
JavaScript
$(function() { $("#tagBoxContainer").dxTagBox({ onValueChanged: function (e) { const previousValues = e.previousValue; const newValues = e.value; // Event handling commands go here } }); });
Angular
HTML
TypeScript
<dx-tag-box ... (onValueChanged)="onValueChanged($event)"> </dx-tag-box>
import { DxTagBoxModule } from "devextreme-angular"; // ... export class AppComponent { onValueChanged (e) { const previousValue = e.previousValue; const newValue = e.value; // Event handling commands go here } } @NgModule({ imports: [ // ... DxTagBoxModule ], // ... })
Vue
<template> <DxTagBox ... @value-changed="onValueChanged" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxTagBox } from 'devextreme-vue/tag-box'; export default { components: { DxTagBox }, methods: { onValueChanged(e) { const previousValues = e.previousValue; const newValues = e.value; // Event handling commands go here } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { TagBox } from 'devextreme-react/tag-box'; class App extends React.Component { constructor(props) { super(props); this.onValueChanged = this.onValueChanged.bind(this); } onValueChanged(e) { const previousValues = e.previousValue; const newValues = e.value; // Event handling commands go here } render() { return ( <TagBox ... onValueChanged={this.onValueChanged} /> ); } } export default App;
NOTE
The
previousValue
and newValue
fields are arrays that contain values taken from the valueExpr data field.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 previousValues = e.previousValue; const newValues = e.value; // First handler of the "valueChanged" event }; const valueChangedHandler2 = function (e) { const previousValues = e.previousValue; const newValues = e.value; // Second handler of the "valueChanged" event }; $("#tagBoxContainer").dxTagBox("instance") .on("valueChanged", valueChangedHandler1) .on("valueChanged", valueChangedHandler2);
See Also
Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you!
We appreciate your feedback.
We appreciate your feedback.