Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows ToggleSwitch to dispatch a subscribable event #6266

Open
Geolim4 opened this issue Apr 17, 2024 · 0 comments
Open

Allows ToggleSwitch to dispatch a subscribable event #6266

Geolim4 opened this issue Apr 17, 2024 · 0 comments

Comments

@Geolim4
Copy link
Contributor

Geolim4 commented Apr 17, 2024

Short description of what this feature will allow to do:

In assets/js/field-boolean.js it would be great if the Promise could dispatch a "subscribable" event:

Replace

        .then(() => { /* do nothing else when the toggle request is successful */ })
        .catch(() => this.#disableField());

by

        .then((responseText) => {
            document.dispatchEvent(new CustomEvent('ea.form.ajax.switch', {
                cancelable: true,
                detail: { response: responseText, field: this.field, error: null}
            }));
        })
        .catch((reason) => {
            this.#disableField();
            document.dispatchEvent(new CustomEvent('ea.form.ajax.switch', {
                cancelable: true,
                detail: { response: null, field: this.field, error: reason}
            }));
        });

What do you thing @javiereguiluz ?

So we can customize the behavior (e.g: with a toaster) and subscribe to the event as we would like to

@Geolim4 Geolim4 changed the title Allow to dispatch a subscribable event Allows ToggleSwitch to dispatch a subscribable event Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant