Disable swipe-left or right for certain elements, with listview swipe widget

0
Is it possible for the listview swipe widget to disable eather swiping right or left, for certain elements list, by adding some sort of class or JS snippet?
asked
3 answers
0

The swipe widget uses the CSS line below to select the ListItem.

const listItems = this.targetNode.querySelectorAll(".mx-listview-item:not(.swipe-connected)");

https://github.com/mendixlabs/listview-swipe/blob/master/src/ListViewSwipe.ts#L111

Like Tim mentions you can add a not selector to filter out listitems with a specific class, e.g. .ignore-listitem. You can add these classes using the dynamic classes widget if the list is not too large, else you might want to use a single javascript snippet.

const listItems = this.targetNode.querySelectorAll(".mx-listview-item:not(.swipe-connected):not(.ignore-listitem)");

 

answered
0

The swipe can be disabled per item, see documentation

 https://github.com/mendixlabs/listview-swipe#disable-swipe

This does not support disable only left or right, though this could be extended in the code, if you have the skills

https://github.com/mendixlabs/listview-swipe/blob/34b409c20f5de89dbc86fc4a109629feb31125be/src/HammerSwipe.ts#L136

Ill guess this code snippet will do the trick

        const prefix = this.options.classPrefix;
        if (event.pointerType === "mouse" 
                || event.target.closest(`.${prefix}-disabled`)
                || (event.target.closest(`.${prefix}-disabled-left`) && event.direction === Hammer.DIRECTION_LEFT)
                || (event.target.closest(`.${prefix}-disabled-right`) && event.direction === Hammer.DIRECTION_RIGHT)) {
            this.panCanceled = true;
        }

Cheers, Andries

answered
-1

Very likely: yes. You would have to dive into the widget, looking for the function that executes the swiping, then look for the selector that selects the objects getting this function added and to that selector add .not(‘.MyClassForMyNonSwipableElements’). After adding MyClassForMyNonSwipableElementsto the objects that  you do want to be fixed.

answered