Material-components-web: MDCDialog:accept is not cancelable

Created on 18 Sep 2017  路  11Comments  路  Source: material-components/material-components-web

I need to post some data from the dialog and if server side validation fails, I need to "reload" dialog content with errors.

The problem is that each "click" on the dialog (buttons, anchor tags, etc..) close it, and I need to re-open, generating an ugly flickering effect.

I thought to intercept 'MDCDialog:accept' event and cancel it preventing the dialog from closing, but accept event is not cancelable.

image

Is there a way to keep open the dialog on accept click ?

help wanted

Most helpful comment

I ended up using my own buttons, and then calling close() on the dialog manually.

All 11 comments

anyone on this? I also don't know how to prevent the dialog box from closing.

+1

+1

+1

I ended up using my own buttons, and then calling close() on the dialog manually.

@ctafield mind sharing a snippet of your implementation ?

Remove mdc-dialog__footer__button--accept from the buttons:

<footer class="mdc-dialog__footer">
      <button type="button" id="dialog-cancel" class="mdc-button mdc-dialog__footer__button">@yield('button_left', 'Cancel')</button>
      <button type="button" id="dialog-confirm" class="mdc-button mdc-dialog__footer__button">@yield('button_right', 'Submit')</button>
</footer>

Then when you initialise, add onclicks:

const dialogElement = document.querySelector('#my-mdc-dialog');
const dialog = new MDCDialog(dialogElement);

dialog.show();

dialogElement.querySelector('#dialog-cancel').onclick = function () {
    // Add your cancel logic here
    dialog.close();
}
dialogElement.querySelector('#dialog-confirm').onclick = function () {
    // Add your cancel logic here
    dialog.close();
}

Hey folks,
is this issue currently being worked on? Any thoughts? From my point of view, it is crucial to control the behaviour of the dialog without hacking around the intended behaviour. Is the behaviour "close dialog on pressing accept" intended, and if yes: why is this ?

Thanks for this nice library !!

I ended up extending MDCDialog, MDCDialogFoundation and Adapter classes injecting my own submitHandler which when it's present then dialog wont close on submit but only when submitHandler returns promise that resolves ... it stays open and shows error when it's a submission failure.
It would be nice if this was all included in MDCDialog and i didn't have to extend it and then maintain the extended code myself

Not being cancelable makes validating dialog content impossible - eg a login dialog or anything that takes user input. Of course, it's easy enough to get around - but I think this should be a requirement of a dialog.

:+1: Yeah, exactly! Thank you!

Not being cancelable makes validating dialog content impossible - eg a login dialog or anything that takes user input. Of course, it's easy enough to get around - but I think this should be a requirement of a dialog.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yapryntsev picture yapryntsev  路  3Comments

patrickrodee picture patrickrodee  路  3Comments

trimox picture trimox  路  4Comments

traviskaufman picture traviskaufman  路  3Comments

abhiomkar picture abhiomkar  路  3Comments