Repository navigation
Description
Issue Overview
A lot of existing meta boxes, especially in enterprise environments, rely on server side validation / sanitation, including meaningful feedback to the user.
This fails in Gutenberg currently.
Steps to Reproduce (for bugs)
-
Setup validation as in https://tommcfarlin.com/post-meta-data-error-messages/ , this requires a CPT 'Location' and a meta box with a single text field.
-
Create a new location, fill in data and save it.
-
API Call will fail with an error "Call to undefined function add_settings_error()", which is used in the example
-
Replace add_settings_error() with a simple string to continue testing.
https://gist.github.com/wsydney76/0dd717fd061908d8037d29ce12569b86 -
Enter a value and save.
-
Then leave the text field blank and save. "Post saved" indicates ok, no error messages shown, the field is still blank.
-
Reload. The old field value is still present.
-
Enter content like 'with tags and save. Tags will be stripped server side, but that is not reflected in the editor. Only a reload shows the altered content.
Gutenberg 1.9
Expected Behavior
The user has to get information about the data being rejected or changed server side. After a "successful" update the content in the editor must not differ from the content in the database.
Current Behavior
If it works at all, the users workflow is broken, potentially resulting in invalid data.
Possible Solution
Documentation is needed:
- Which kind of implementations of server side validation breaks in Gutenberg?
- How can it be changed to work in Gutenberg?
Activity
danielbachhuber commentedon Mar 30, 2018
Related #5590
@wsydney76 Can you clarify what you mean by this?
danielbachhuber commentedon Apr 4, 2018
Created #5975 to define a formal notices API.
danielbachhuber commentedon Aug 22, 2018
In thinking through this further, I'm not sure it will be possible to support this formally in Gutenberg.
We could potentially detect calls to
add_settings_error()in thePOSTrequest to save meta boxes. However, there's no formal API between calls toadd_settings_error()and their display, so I'm not sure what Gutenberg would do if it detected these calls. Reloading the meta box part of the page would be insufficient, becauseadmin_noticesis in the header of the page.With this being said, someone could produce a plugin implementation that replicates the validation behavior, and we could refer to that as a recommended compatibility shim. I'm not sure Gutenberg could do something like this correctly by default, but a workflow where the user has to install and test the plugin would also verify the validation works for them as expected.
mcsf commentedon Aug 30, 2018
Came here via #4063. @danielbachhuber, I noticed you self-assigned this one. Out of your curiosity, what's your plan here?
danielbachhuber commentedon Aug 30, 2018
Document and close, most likely.
4 remaining items
[-]Meta boxes: server side validation fails[/-][+]Meta boxes: server side validation with `add_settings_error` fails[/+][-]Meta boxes: server side validation with `add_settings_error` fails[/-][+]Meta boxes: server side validation with `add_settings_error` isn't possible[/+]ryanwelcher commentedon Feb 7, 2023
Is this issue still relevant?
ndiego commentedon May 25, 2023
This issue was reviewed in today's Documentation Issue Scrub. Given the inactivity of this issue in the last couple of years, I am going to close. However, if anyone feels like this should be reopened, please don't hesitate to do so. Thanks!