Skip to content

Provide an API to validate block input, either client-side or server-side #4063

@ghost

Description

Issue Overview

Sometimes it is crucial to validate input values on the server side, e.g. check if an email address is valid within the company by checking against an LDAP-Directory. (Server side because "Never trust the client" rules).

I could not figure out (overlooked?) a way to do that with Gutenberg.

Steps to Reproduce

  1. Hook into rest api (pre_insert_post?) and return an error, something like
    return new WP_Error( 'rest_invalid_param', 'E-Mail not found in directory', array( 'status' => 400) );
  2. 'Updating failed' is shown, but not the specific error message.

Possible Solution

  • Document how to return an error (better a list of errors) correctly.
  • Display the error messages.

In a second step it would be helpful to trigger a JS event in the corresponding block, so that a visual feedback can be given in the right place.

PS.
Is there some kind of validation framework present/planned in Gutenberg that i did not see?

Metadata

Metadata

Assignees

No one assigned

    Labels

    REST API InteractionRelated to REST API[Feature] Block APIAPI that allows to express the block paradigm.[Feature] ExtensibilityThe ability to extend blocks or the editing experience[Type] EnhancementA suggestion for improvement.[Type] QuestionQuestions about the design or development of the editor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions