DevExtreme Vue - Handle the Value Change Event
To process a new RadioGroup 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
$(function() { $("#radioGroupContainer").dxRadioGroup({ onValueChanged: function (e) { var previousValue = e.previousValue; var newValue = e.value; // Event handling commands go here } }); });
Angular
<dx-radio-group [dataSource]="dataSource" [(value)]="radioGroupValue" (onValueChanged)="handleValueChange($event)"> </dx-radio-group>
import { DxRadioGroupModule } from "devextreme-angular"; // ... export class AppComponent { dataSource = ["Low", "Normal", "Urgent", "High"]; radioGroupValue = dataSource[1]; handleValueChange (e) { const previousValue = e.previousValue; const newValue = e.value; // Event handling commands go here }; } @NgModule({ imports: [ // ... DxRadioGroupModule ], // ... })
Vue
<template> <DxRadioGroup :data-source="dataSource" :value.sync="radioGroupValue" @value-changed="handleValueChange" /> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import { DxRadioGroup } from 'devextreme-vue/radio-group'; const items = ["Low", "Normal", "Urgent", "High"]; export default { components: { DxRadioGroup }, data() { return { dataSource: items, radioGroupValue: items[1] }; }, 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 { RadioGroup } from 'devextreme-react/radio-group'; class App extends React.Component { constructor(props) { super(props); this.dataSource = ["Low", "Normal", "Urgent", "High"]; this.state = { value: this.dataSource[1] }; this.handleValueChange = this.handleValueChange.bind(this); } handleValueChange(e) { const previousValue = e.previousValue; const newValue = e.value; // Event handling commands go here this.setState({ value: newValue }); } render() { return ( <RadioGroup dataSource={this.dataSource} value={this.state.value} 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.
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 }; $("#radioGroupContainer").dxRadioGroup("instance") .on("valueChanged", valueChangedHandler1) .on("valueChanged", valueChangedHandler2);
See Also
- Handle Events: Angular | Vue | React | jQuery | AngularJS | Knockout | ASP.NET MVC 5 | ASP.NET Core
- RadioGroup - Customize Item Appearance
- RadioGroup Demos
- RadioGroup API Reference
If you have technical questions, please create a support ticket in the DevExpress Support Center.