falsandtru / pjax-api

The advanced PJAX superior to SPA.
https://falsandtru.github.io/pjax-api/
Apache License 2.0
318 stars 28 forks source link

Adding more events, preventing unload on condition #42

Closed georgehristov closed 4 years ago

georgehristov commented 4 years ago

Have you considered adding more events to the list (as in defunkt/jquery-pjax)? Is there a way to prevent request in case some conditions not met? For instance a dirty form not saved.

falsandtru commented 4 years ago

Probably you should call event.preventDefault().

georgehristov commented 4 years ago

Tried it put it did not work as expected. And in any case it is better for have the pjax:click and pjax:clicked events to prevent even sending the request to the server

falsandtru commented 4 years ago

I don't provide such events. You have to call that method to disable events in capture phase. This pjax ignores disabled events. I designed event canceling in this way.

falsandtru commented 4 years ago

However, anyway there is no way to prevent browser back/forward without handling beforeunload events. And since pjax usually disables browser functions to keep form data, I don't use pjax with form pages and I recommend that pjax users do so.