"Auto" preview option that updates on field blur

Created on 15 March 2023, over 1 year ago
Updated 25 April 2023, about 1 year ago

Problem/Motivation

Excellent work on this so far, really exciting to see this taking shape! As I was watching the demo video, I noticed that it was necessary to keep hitting the Preview button to see the changes take effect. As a content author, I would likely prefer to see that update automatically.

User Story

As a content creator/editor, I want to be able to work with content and have the preview refresh for me automatically.

Proposed resolution

Have an "Auto" setting that would automatically update the preview whenever fields lose focus in the entity form. There are a few fields that it would make sense to omit, such as publish toggles, workflow state, and basically anything in the right sidebar. Maybe the module's settings could make this configurable also, although the configurable piece could be added later.

Remaining tasks

  • Discuss which event would be best to use when triggering an update to the preview.
  • Implement the interaction / behavior
  • Allow for an exclusion list of fields that shouldn't trigger an update to preview.
  • Consider how to communicate what fields update and what fields do not update the preview to content workers.

User interface changes

Support a workflow where content editors seldom have to click the refresh button to see a refreshed preview.

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mandclu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mandclu
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    We whole-heartedly agree @mandclu. In fact this is the main thing we want to accomplish in Phase 2.

    Previously, while discussing this feature with @isramv, he suggested that we utilize the "debounce" technique to trigger an update to the preview once a user "stops typing". While the specific event that we use to trigger a preview could be a bunch of different things, one thing is sure. We want this feature too.

    We meet every other Wednesday in the #preview channel in Slack to talk about progress. You're welcome to join us and discuss.

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    Updated issue to capture most of our current thinking.

  • πŸ‡¨πŸ‡¦Canada mandclu

    FYI this is all that's required for a basic implementation of the blur-triggered updates:

    (function (Drupal, once) {
      'use strict';
    
      Drupal.behaviors.samePagePreviewAuto = {
        attach: function (context, settings) {
          once('samePagePreviewAuto', '.node-form input.form-element', context).forEach(function (element) {
            element.addEventListener("blur", function () {
              forceRefresh();
            });
          });
          once('samePagePreviewAuto', '.node-form .ck-editor__editable_inline', context).forEach(function (element) {
            element.addEventListener("blur", function () {
              forceRefresh();
            });
          });
    
          function forceRefresh() {
            const component = document.querySelector('[data-drupal-selector="edit-refresh"]');
            if (component) {
              component.dispatchEvent(new Event("click"));
            }
          }
        }
      };
    }(Drupal, once));
    

    I did try the debounce approach, particularly for the WYSIWYG. I couldn't get it to work, I think because I was also struggling to get the CKEditor instances. For the above I settled on selecting the wrapper div around the inner content, which does receive focus but doesn't "change" for the sake of JS.

  • πŸ‡¨πŸ‡¦Canada mandclu

    Moving this to the 2.0.x branch

  • @mandclu opened merge request.
  • Status changed to Needs review about 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    First draft of the auto preview. Theoretically we could add a toggle that if enabled would hide the manual refresh button, but since there has been talk of moving those controls anyway, leaving that for now.

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    Thank you.

    Yes, the button is likely going away in version 2, to be replaced by a checkbox. There are a few reasons for this.

    First, it's important to give users relief from using this feature if it bombards them with audible text (when using screen readers) or is too visually stimulating.
    Second, it might be a good to have a failsafe if the mobile / small form factor experience breaks content creation workflows on those devices.

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    Did some manual testing.

    I discovered that updating an image does not update the preview. The updated image is shown, however, when I update a text field.

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    While testing I looked at the fields that are getting the "samePagePreviewAuto" behavior applied to them. A lot of the fields that in the "Meta" section (such as path-alias) are also getting the behavior.

    I wonder if strategically it would be better to have a function in the .module that is responsible for gathering up all the fields that should getting the auto refresh behavior then crafting our callback to use that inserted class.

  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    Much improvement. Let's get this in and build off of this.

  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    Merged.

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul
  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024