Support

Account

Home Forums Gutenberg Required fields in Gutenberg editor Reply To: Required fields in Gutenberg editor

  • The solution I came up with as a fix was to use jquery to disable the publish / update button if the forms on the page don’t validate. It’s only briefly tested so I wouldn’t recommend on a production site without testing.

    Make sure that this script is enqueued via file or is in <script> tags in the admin footer on the gutenberg edit page.

    
    jQuery(document).ready(function($) {
        $(window).bind("load", function () {
            switch_publish_button_on_valid()
        });
        $("form :input").change(function() {
                switch_publish_button_on_valid();
            });
        function switch_publish_button_on_valid(){
            if($('form.metabox-location-normal')[0].checkValidity()){
                $('button.is-primary').removeAttr('disabled');
            } else {
                $('button.is-primary').attr('disabled', 'disabled');
            }
        }
    });