All docs
V21.1
21.2
21.1
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Handle the Value Change Event

By default, the Lookup applies a value immediately after an end user chooses an item from the drop-down menu. To change this behavior and apply the value after a user clicks the "Apply" button, assign 'useButtons' to the applyValueMode property.

jQuery
JavaScript
const lookupData = [
    { id: 1, country: "Afghanistan" },
    { id: 2, country: "Albania" },
    // ...
];

$(function() {
    $("#lookupContainer").dxLookup({
        dataSource: lookupData,
        valueExpr: 'id',
        displayExpr: 'country',
        applyValueMode: 'useButtons'
    });
});
Angular
HTML
TypeScript
<dx-lookup
    [dataSource]="lookupDataSource"
    valueExpr="id"
    displayExpr="country"
    applyValueMode="useButtons">
</dx-lookup>
import { DxLookupModule } from "devextreme-angular";
// ...
export class AppComponent {
    lookupDataSource =  [
        { id: 1, country: "Afghanistan" },
        { id: 2, country: "Albania" },
        // ...
    ];
}
@NgModule({
    imports: [
        // ...
        DxLookupModule
    ],
    // ...
})
Vue
<template>
    <DxLookup
        :data-source="lookupData"
        value-expr="id"
        display-expr="country"
        apply-value-mode="useButtons"
    />
</template>

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

import { DxLookup } from 'devextreme-vue/lookup';

export default {
    components: {
        DxLookup
    },
    data() {
        return {
            lookupData: [
                { id: 1, country: 'Afghanistan' },
                { id: 2, country: 'Albania' },
                // ...
            ]
        };
    }
}
</script>
React
import React from 'react';
import 'devextreme/dist/css/dx.light.css';

import { Lookup } from 'devextreme-react/lookup';

const lookupData = [
    { id: 1, country: 'Afghanistan' },
    { id: 2, country: 'Albania' },
    // ...
];

class App extends React.Component {
    render() {
        return (
            <Lookup
                dataSource={lookupData}
                valueExpr="id"
                displayExpr="country"
                applyValueMode="useButtons"
            />
        );
    }
}

export default App;

To process a new Lookup 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
JavaScript
$(function() {
    $("#lookupContainer").dxLookup({
        onValueChanged: function (e) {
            const previousValue = e.previousValue;
            const newValue = e.value;
            // Event handling commands go here
        }
    });
});
Angular
HTML
TypeScript
<dx-lookup ...
    (onValueChanged)="onValueChanged($event)">
</dx-lookup>
import { DxLookupModule } from "devextreme-angular";
// ...
export class AppComponent {
    onValueChanged (e) {
        const previousValue = e.previousValue;
        const newValue = e.value;
        // Event handling commands go here
    }
}
@NgModule({
     imports: [
         // ...
         DxLookupModule
     ],
     // ...
 })
Vue
<template>
    <DxLookup ...
        @value-changed="onValueChanged"
    />
</template>

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

import { DxLookup } from 'devextreme-vue/lookup';

export default {
    components: {
        DxLookup
    },
    methods: {
        onValueChanged(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 { Lookup } from 'devextreme-react/lookup';

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

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

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

    render() {
        return (
            <Lookup ...
                onValueChanged={this.onValueChanged}
            />
        );
    }
}

export default App;

View Demo

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

$("#lookupContainer").dxLookup("instance")
    .on("valueChanged", valueChangedHandler1)
    .on("valueChanged", valueChangedHandler2);
See Also