2

When ever the user leaves a page, I try to open a paper-dialog asking for the confirmation.

canLeavePage : function(){ 
this.$.paperDialog.open()
}

where canLeavePage triggers before the page is changed. But canLeavePage doesnt wait until the paperDialog is closed.

Is there anyway where I can wait for the result of the paperDialog in canLeavePage function and then proceed?

Shrikey
  • 858
  • 3
  • 11
  • 34
  • just try to find something on google.. there are plenty of topics about it. And then integrate it into paperDialog... http://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page – Kuba Šimonovský Apr 21 '17 at 08:12
  • @KubaŠimonovský Polymer's Paper-Dialog should be opened instead of a normal javascript alert. Based on the Ok or Cancel click in the paper-dialog result has to be returned in the canLeavePage.. In fact I did lot of google and as a last resort, posted a question in SO. – Shrikey Apr 21 '17 at 08:14
  • well, google chrome won't let you open anything else . It has it's own alert which (propably) can't be overriden. I don't know about other browsers, but what you are asking is against user friendly rules. No one ever want to be stopped from leaving a website – Kuba Šimonovský Apr 21 '17 at 08:49
  • @KubaŠimonovský .. Oops.. I should have mentioned it earlier. The alert has to be shown when the user moves from one page to another. Not on leaving the website. – Shrikey Apr 21 '17 at 09:37
  • oh man... that's absolutely different... i just didn't undestand you .. But you have to tell more what routing you are using. Are you using some library like page.js or native polymer app-route ? – Kuba Šimonovský Apr 21 '17 at 09:49
  • In short, all the views are changed using iron-pages and app-route, so whenever a route change occurs, in the route change handler, i will call a specific method (canLeavePage) which exists in all the pages. If it returns true, i will allow the page change, or else i will change the route to the oldpage. – Shrikey Apr 21 '17 at 10:00
  • hard to say when i don't see the code. but what you will have to do, is changing property values. Let's say you create one new property, which will change whnever user change page. This property will have observer which will call function canLeavePage and if this function returns true, then you will have to change final property which is binded to app-route and iron-pages. – Kuba Šimonovský Apr 21 '17 at 10:33

0 Answers0