-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta boxes: server side validation with add_settings_error
isn't possible
#3964
Comments
Related #5590
@wsydney76 Can you clarify what you mean by this? |
@danielbachhuber Sure, as far as i remember the error occurred when saving the post and with it the meta boxes, so the term "API Call" may be incorrect for the meta boxes part. The call to add_settings_error is in part 4 of https://tommcfarlin.com/post-meta-data-error-messages/ |
Created #5975 to define a formal notices API. |
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 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. |
Came here via #4063. @danielbachhuber, I noticed you self-assigned this one. Out of your curiosity, what's your plan here? |
Document and close, most likely. |
@chrisvanpatten Can you document this in https://github.com/danielbachhuber/gutenberg-migration-guide (when you have a chance) and then we can close? |
Also relates to discussion about the Notices API in Slack today. It'd be nice to see this addressed but until then I've put a note in #11251 and I'm going to rename the ticket for clarity. |
add_settings_error
fails
add_settings_error
failsadd_settings_error
isn't possible
Is this issue still relevant? |
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! |
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:
The text was updated successfully, but these errors were encountered: