Skip to content
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

Required fields in Gutenberg blocks #90

Open
philbraun opened this issue Nov 23, 2018 · 19 comments
Open

Required fields in Gutenberg blocks #90

philbraun opened this issue Nov 23, 2018 · 19 comments

Comments

@philbraun
Copy link

Currently, there seems to be no way to get fields in Gutenberg blocks act as required.
In my limited testing, under ACF 5.8 Beta 2 posts were saved regardless of any "required" setting.

Under Beta 3, setting a post relationship field to required seems to be able to do bad things – I've just had 3 posts go to an uneditable state with instant
Fatal error: Uncaught Error: Maximum function nesting level of '256' reached, aborting! in /Users/philby/Sites/mysite/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-helpers.php on line 144
(not 100% sure this is related to the required setting yet, but not turning it on seems to make things much more stable).

@elliotcondon
Copy link
Contributor

@philbraun Thanks for the topic.

Currently, there seems to be no way to get fields in Gutenberg blocks act as required.
Correct. Field validation is not yet possible with blocks but this will be something to add in the future.

Under Beta 3, setting a post relationship field to required seems to be able to do bad things.
I've just tested this out but was unable to replicate any error. The code in question (line 144) relates to the acf_validate_setting() function which is used for backwards compatible name changes.

Perhaps you have some code in your theme/plugins that are hooked into this filter and causing an infinite loop?

@philbraun
Copy link
Author

@elliotcondon Still testing, but you're right, it is almost certainly related to a Theme: I'm using Genesis (2.7.1), and it's the 3 Genesis metadata boxes (SEO, Layout Settings, Scripts) that are crashing. Hide them all, and it works.

However, I have a suspicion that this Theme metaboxes infinite loop only happens when using ACF Blocks, I haven't been able to get them to crash using any other Block yet.

Later today I'll recreate your demo testimonial block and see what happens.

@jnicol
Copy link

jnicol commented Apr 11, 2019

@elliotcondon

Correct. Field validation is not yet possible with blocks but this will be something to add in the future.

In my tests (5.7.13 and 5.8 RC 1 under WP 5.1.1) it is not just fields within blocks whose "required" setting is ignored when using the Gutenberg editor. Regular ACF custom fields are not validated either i.e. validation doesn't work at all, anywhere. Is this a known bug?

EDIT: Digging deeper I found #113, from which I gather that WP does not currently have a API for AJAX validation. Fingers crossed that the Gutenberg team pull something together in time for ACF 5.8's official release. Field validation seems like quite a major feature to drop.

@benbowler
Copy link

Still no API as of 7 August 2019 #113

@Fcog
Copy link

Fcog commented Sep 6, 2019

Is there a workaround to make work the acf marked as required?

@timnolte
Copy link

timnolte commented Nov 7, 2019

This is a huge problem that seems like it should be a priority. In order to deliver a project in time I may be forced to drop the block editor altogether. :-/

@timnolte
Copy link

timnolte commented Nov 7, 2019

BTW, it appears this issue with validation appears to have been open for a year? Really?

@elliotcondon
Copy link
Contributor

Hi @timnolte

Unfortunately, it seems the Gutenberg ticket regarding this API has gone stale. I just checked and can see a few more similar tickets have been opened, but with no solution yet.

@pwkip
Copy link

pwkip commented Mar 27, 2020

@elliotcondon I'm not sure, but could it be that the Gutenberg team will not be implementing validation as we know and love it, but wants us to rely on the lockPostSaving action (#10649) as mentioned in #11967?

Of course, some feedback to the user on why the post cannot be saved would be super helpful and might not be straight forward to implement in ACF..

@landwire
Copy link

Is there any news on this? Just came across this myself and wondered why the fields were not validating when used in a block.

@elliotcondon
Copy link
Contributor

Hi @landwire. No news to share just yet, except that we will begin work in this area shortly now that 5.9 has been release - which includes our initial PHP validation solution for the Gutenberg editor 👍

@QuanTumli
Copy link

Is there any news related to this issue?

@CodingSamurai
Copy link

CodingSamurai commented Jul 13, 2021

Hi @landwire. No news to share just yet, except that we will begin work in this area shortly now that 5.9 has been release - which includes our initial PHP validation solution for the Gutenberg editor 👍

@elliotcondon It's been almost a year do you have ANY progress on fixing this? This is a MAJOR regression that's been open for almost 1000 days!

@sphere-radio-it
Copy link

Still no change?

@lgladdy
Copy link
Member

lgladdy commented Jan 20, 2022

Hey everyone,

There's more information on this issue here: #113

There's lots of links on that thread to various Gutenberg/WordPress issues which have prevent us being able to jump in with an elegant solution to this issue.

That said, this is an issue we want to solve as soon as we can, and we hope to make progress on it soon. We'll share more information as soon as we know in which release this will fall under!

Thanks,
Liam

@timnolte
Copy link

@lgladdy thanks for the update. I have suspected that the challenge has been a lot to do with Gutenberg.

@jgsanchezg
Copy link

jgsanchezg commented Oct 15, 2024

Hello everyone.
I just saw that back in May 24, 2024 there was an update to ACF PRO 6.3 where it is claimed that the validation was now working on that version, however, if I try to save a gutenberg block with required fields in blank it still allows me to save the block, therefore, I don't think it is fixed yet, right?
Basically to replicate this issue I go to my page to edit, move around the blocks by using Tab key, I skip filling the required fields and inmediatelly hit on the Save button, the validation doesn't happen and then the post is saved.
Does it also happen to you guys?

Also, I was wondering if this workaround would be a good recomendation for this issue: https://support.advancedcustomfields.com/forums/topic/required-fields-in-gutenberg-editor/#post-155852

@Log1x
Copy link

Log1x commented Oct 16, 2024

Basically to replicate this issue I go to my page to edit, move around the blocks by using Tab key, I skip filling the required fields and inmediatelly hit on the Save button, the validation doesn't happen and then the post is saved.
Does it also happen to you guys?

For some reason validation isn't enabled by default unless the blocks are registered with block.json. See Log1x/acf-composer@1dfc497 for an example with PHP registration.

@jgsanchezg
Copy link

Hello @Log1x thanks for that! But actually I am using block.json, I even tried to add that piece of code to it but I'm facing the same situation still :(
This is my block.json
{ "$schema": "https://advancedcustomfields.com/schemas/json/main/block.json", "apiVersion": 3, "name": "blocks/recent-resources-section", "title": "Recent Resources Section", "description": "This block loads the 3 most recent posts from the Resources post type selected.", "keywords": ["resources section", "resources", "recent"], "category": "gutenberg-blocks", "icon": "media-document", "validate": true, "acf": { "mode": "edit" } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests