Skip to content

Allow developer to override choice/item removal #1351

@craigpipeandpiper

Description

@craigpipeandpiper

Is your feature request related to a problem? Please describe.
Right now you can't prevent removal of a choice from the list with a prompt or confirmation. Backspace or close proceeds to remove the item without prompting at all times. Some use cases need us to prompt to user with an 'are you sure' as removing the item/choice has ramifications to other parts of the page.

Describe the solution you'd like
Add an async function that lets the developer override the deletion via a returned boolean. for example:

    var DEFAULT_CONFIG = {
        items: [],
        // ....
        shouldDelete: function() { return true; },
};

and:

        Choices.prototype._handleButtonAction = async function (element) {
            var _this = this;
            var items = this._store.items;

            // ....

            let shouldRemove = true;
            if(this.config.shouldDelete) {
                shouldRemove = await this.config.shouldDelete([itemToRemove]);
            }
            if(!shouldRemove) {
                return;
            }

Describe alternatives you've considered
I've tried attaching overriding events to the elements in the DOM, but the combination of events, and the fact that it is mousedown not click, plus having to handle backspace, makes it prohibitive to get right.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions