Suppress validation errors being shown in the preview

Created on 27 March 2023, over 1 year ago
Updated 21 March 2024, 9 months ago

Problem/Motivation

Validation errors shouldn't be shown in the preview. Currently this is most obvious with the Title field, but the same behaviour will be evident on any required fields.

Steps to reproduce

With Same Page Preview installed, click the toggle link to open the preview before providing any input. Notice the error message that the title field is required.

Proposed resolution

Suppress the display of messages within the preview window. If there are ultimately validation messages, those should be shown when the user submits the content.

✨ Feature request
Status

Needs review

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mandclu

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

Merge Requests

Comments & Activities

  • Issue created by @mandclu
  • @mandclu opened merge request.
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Moving this to the 2.0.x branch. Also, I think we need to figure out how to suppress these errors instead of just hiding them via CSS.

    I know that the preview is built from the form state, which itself has methods available related to validation, namely:

    setValidationEnforced()
    setLimitValidationErrors()
    setValidationComplete()

    I tried using those within a copy of the form state in this module's compilePreview() function and then sending that to the tempstore $store_private->set() call at the end of the function, but it didn't seem to work. If we can get it working, however, I think this approach would be much better.

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

    I believe this is also addressed in 2.1.x - marking as fixed.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Tested this in 2.1.0 and it still exhibits the same behavior.

  • πŸ‡ΊπŸ‡ΈUnited States brianperry

    Whoops my bad. On initial load in Gin with the preview open by default I don't see the validation error, but I do see it if I refresh the preview.

  • πŸ‡¨πŸ‡¦Canada mandclu

    The error that I find most disruptive to the user experience is the error thrown when using an image field, such as when creating an article with a standard install of Drupal. You see the preview and everything thing looks great, but once you upload an image the only thing you see is the error about missing alt text.

    IIRC I also tried this with Inline Form Errors installed, but it still didn't work, though that was with an older version.

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I started a new MR targeting 2.1.x, removing all status messages.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Before the patch, an image field breaks the preview when an image is uploaded, showing only the validation error:

    After the patch, the validation error isn't shown, but the preview is not show either. The result is even more confusing to the user, since it is effectively a black preview:

    We need to actually suppress the errors, not just hide them.

  • Status changed to Needs review over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I was able to successfully suppress all validation errors by decorating and adding preview form-specific logic to the form_error_handler service.

  • Status changed to RTBC over 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    This is great, and works exactly the way I had hoped.

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

    Back in action, reviewing...

  • Status changed to Needs work over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I just found out this suppresses all errors on node forms.

  • Status changed to Needs review over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    Fixed!

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

    I'll have to manually test this.

Production build 0.71.5 2024