JavaScript/jQuery Stepper - Cancel a Step Change
You can cancel a step change in the Stepper onSelectionChanging event handler. To do this, assign a Boolean value or Promise that returns a Boolean to SelectionChangingEvent.cancel. The code snippet below implements a DevExtreme confirm dialog that asks users for confirmation before moving the component's selected step back.
index.js
- $("#stepper").dxStepper({
- // ...
- onSelectionChanging: function (e) {
- const { component, addedItems, removedItems } = e;
- const { items = [] } = component.option();
- const removedIndex = items.findIndex((item) => item === removedItems[0]);
- const addedIndex = items.findIndex((item) => item === addedItems[0]);
- const isMoveBack = addedIndex < removedIndex;
- if (isMoveBack) {
- e.cancel = DevExpress.ui.dialog
- .confirm(`<div>Are you sure you want to go back?</div>`. "")
- .then((isChangeConfirmed) => {
- return !isChangeConfirmed;
- });
- }
- }
- })