Keep users from unintentionally navigating away from node preview pages.

flobruit - March 26, 2008 - 22:14
Project:Drupal
Version:7.x-dev
Component:node system
Category:feature request
Priority:normal
Assigned:flobruit
Status:needs work
Description

As suggested by drumm in the development mailing list, altering the preview page using jquery is one way to keep users from losing the data they just entered when navigating away from the preview page.

There are two possible approaches here, disable links, or ask for confirmation when a link is clicked. Handling confirmation when a user navigates away would require some browser-specific javascript code.

/**
* Disable links inside of a node preview, to ensure that users don't
* accidentally go to a different page a lose their content.
*/
Drupal.behaviors.nodePreviewProtect = function(context) {
  $("div.preview a", context).click(function() {
    // Do not navigate away from the page.
    return false; 
  }).attr("title", Drupal.t("Links are disabled during preview."));
}

/**
* Make sure that users don't go to a different page and unintentionally
* lose their content.
*/
Drupal.behaviors.nodePreviewProtect = function(context) {
  $("div.preview a", context).click(function() {
    if (!confirm(Drupal.t("Are you sure you want to navigate away from this page?"))) {
      // Do not navigate away from the page.
      return false;
    }
  });
}

Attached path implements the second option.

AttachmentSize
node_preview_protect.patch1.19 KB

#1

earnie - March 27, 2008 - 13:19

subscribing. Looks good visually. I'll give it a go later.

#2

meba - March 27, 2008 - 22:02

Works, but still fixes just only one scenario:

> Does anybody know why when previewing a node its title
> appears with a link to "/node"? I have seen some users
> accidentally clicking on this link and loosing their content.

AFAIK, Google Docs are alerting user whenever he clicks any link in the page or a back button. This may be a better, more general approach.

#3

moshe weitzman - March 28, 2008 - 01:08

This used to be a big problem in prior releases since the back button did not work as expected and your post was lost. today, we issue proper headers so i have not seen a browser that discards your form fields by regenerating a new page. i don't think an alert is needed anymore. if you do, please proviude steps to reproduce a back button failure.

#4

catch - March 28, 2008 - 10:42

I think there's another issue dealing with the node title link in previews, I'd be tempted to make it not a link for that specific case.

Overall, I agree with never use a warning - of course that would also require an undo implementation, which we don't have.

If we're going to have warnings though, it should probably come in along with the modal dialogs patch (and maybe replace delete confirmation pages as well as handling 'are you sure'). Definitely needs to be consistently applied though either way - we can't have a situation where you click one link and get warned, then another link and don't get warned and never know what's going to happen click by click.

#5

catch - March 28, 2008 - 10:42
Status:needs review» needs work
 
 

Drupal is a registered trademark of Dries Buytaert.