4

See the following html in a Polymer app:

<paper-dialog id="confirmation" modal auto-fit-on-attach>
    <h2><spring:message code="confirmation" /></h2>
    <p>Are you sure ?<p>
    <div class="buttons">
        <paper-button dialog-confirm><spring:message code="yes" /></paper-button>
        <paper-button dialog-dismiss><spring:message code="no" /></paper-button>
    </div>
</paper-dialog>

And the following JavaScript:

document.querySelector("#confirmation p").innerText = (message === undefined) ? "No message" : message;
document.getElementById("confirmation").toggle();

How to get the return value ´confirmed´ from the dialog?

1 Answer 1

4

You normally attach a handler to the iron-overlay-closed event on the dialog to determine whether it was confirmed as the paper-dialog implements the PaperDialogBehavior.

So something like:

<template is="dom-bind" id="scope">
    <paper-dialog id="confirmation" modal auto-fit-on-attach on-iron-overlay-closed="dismissDialog">
        <h2><spring:message code="confirmation" /></h2>
        <p>Are you sure ?<p>
        <div class="buttons">
            <paper-button dialog-confirm><spring:message code="yes" /></paper-button>
            <paper-button dialog-dismiss><spring:message code="no" /></paper-button>
        </div>
    </paper-dialog>
</template>

<script>
  (function() {
    var scope = document.querySelector('#scope');

    scope.dismissDialog = function(e) {
      console.log(e.detail.confirmed);

      if (e.detail.confirmed) {
        // confirmed logic goes here
      }
    }
  })();    
</script>

Not the answer you're looking for? Browse other questions tagged or ask your own question.