Search code examples
javascriptarraysecmascript-6dialogpolymer

JavaScript - Polymer: this.splice after paper-alert-dialog


I'm trying to add a paper-alert-dialog when deleting an item from the array, but I cannot seem to understand how this works.

I have the following function that works now, without the dialog:

_delete(e) {
          var index = this.todos.indexOf(e.model.item);
          this.splice('todos', index, 1)
          this.$.grid.clearCache();
          }

if I set this function to fire on-tap, it works like a charm, but I am trying to add a confirmation dialog. So, I made a new function that first calls the alert dialog:

_confdel() {
this.$.Delconfirm.open();
}

If I set the paper-button on-confirm="_delete()" this won't work. It will trigger the alert-dialog, but paper-dialog on-confirm won't delete the entry when it fires _delete.

What am I doing wrong here?

Plnkr: https://plnkr.co/edit/UXNhfLU4DrDkBdpeIkuQ?p=preview


Solution

  • instead of calling on-confirm="_delete()" you have to only tell the name of the function like: on-confirm="_delete".

    I assume your confirm-dialog and _delete function are in the same element si it can call this._delete