Required field is stored empty
- This topic has 4 replies, 2 voices, and was last updated 2 years, 2 months ago by
Peter.
-
AuthorPosts
-
February 8, 2023 at 4:33 PM #40445
[email protected]
ParticipantHi, I am defining a field as require and although it is empty, I can save the post without any error, having that field empty. I am getting in the console, errors like this, but I don't know if they are related to the problem.
Here is the code with the definition of the fields
$meta_boxes[] = [ 'title' => __('Hero', DOMAIN), 'id' => 'sng-hero', 'description' => __('Hero', DOMAIN), 'type' => 'block', 'icon' => 'awards', 'category' => 'sng-blocks', 'render_template' => PATH . '/gutenberg-blocks/hero/template.php', 'preview' => [ 'esPreview' => '1', 'capture' => get_template_directory_uri() . '/assets/img/previews/hero.png', ], 'enqueue_assets' => function () { }, 'supports' => [ 'customClassName' => true ], 'fields' => [ [ 'type' => 'single_image', 'id' => 'image', 'name' => __('Imagen', DOMAIN) ], [ 'type' => 'text', 'id' => 'title', 'name' => __('Título',DOMAIN), 'required' => true ], ] ]
Greetings and thank you
February 8, 2023 at 5:58 PM #40446[email protected]
ParticipantSorry for the previous errors in the post. This is the console error:
Block validation: Block validation failed for
core/button
(
Content generated bysave
function:Block validation: Block validation failed for
core/media-text
Content generated bysave
function:And this is the code
$meta_boxes[] = [ 'title' => __('Hero', DOMAIN), 'id' => 'sng-hero', 'description' => __('Hero', DOMAIN), 'type' => 'block', 'icon' => 'awards', 'category' => 'sng-blocks', 'render_template' => PATH . '/gutenberg-blocks/hero/template.php', 'preview' => [ 'esPreview' => '1', 'capture' => get_template_directory_uri() . '/assets/img/previews/hero.png', ], 'enqueue_assets' => function () { }, 'supports' => [ 'customClassName' => true ], 'fields' => [ [ 'type' => 'single_image', 'id' => 'image', 'name' => __('Imagen', DOMAIN) ], [ 'type' => 'text', 'id' => 'title', 'name' => __('Título',DOMAIN), 'required' => true ], ] ]
February 8, 2023 at 10:29 PM #40451Peter
ModeratorHello there,
I see the issue when the post is still saved but the field title is empty, I can also reproduce it on my local site. But I do not see the issue with
core/button
andcore/media-text
like your screenshot.If you remove the MB block, does the issue persist?
February 9, 2023 at 10:53 PM #40467[email protected]
ParticipantHi again,
In local I don't reproduce the core/button, core/media-text.
The require field still doesn't work correctly and it doesn't work on custom fields of custom taxonomies either.
February 10, 2023 at 9:55 PM #40478Peter
ModeratorHello,
Thanks, I see the issue with the validation in the block and I've escalated this issue to the development team to fix this. It will be included in the next update or so.
-
AuthorPosts
- You must be logged in to reply to this topic.