Support

Account

Forum Replies Created

  • Hi @razz
    Not sure, if this is still a concern, but here is what worked for me.
    Just removing event listener that caused ignoring of validation.
    Put this in your JS

    
    acf.addAction('prepare', function(){
        acf.validation.removeEvents({
            'click #save-post': 'onClickSave',
        });
    });
    

    or if you don’t know how or where, add this to your functions.php

    
    add_action('acf/input/admin_footer', function(){
        ?>
        <script>
            acf.addAction('prepare', function(){
                acf.validation.removeEvents({
                    'click #save-post': 'onClickSave',
                });
            });
        </script>
        <?php
    }, 10);
    
  • Just a little error in my code. There shouldn’t be shift() on line 3.

    acf.add_filter('validation_complete', function (json) {
        if (json.errors) {
            var input = json.errors[0].input;
            $('[name="' + input + '"]').parents('.acf-field').each(function(){
                var $tab = $(this).prevAll('[data-type="tab"]').first();
                if($tab.length){
                    var tab_data_key = $tab.attr('data-key');
                    $tab.prevAll('.acf-tab-wrap').find('a[data-key="' + tab_data_key + '"]').click();
                }
            });
        }
    
        return json;
    });
  • This one opens only the first error and then acf scrolls to it. But it works also with nested tabs and in repeaters. Probably in layouts too, but I haven’t tested it.

    
    acf.add_filter('validation_complete', function (json) {
        if (json.errors) {
            var input = json.errors.shift().input;
            $('[name="' + input + '"]').parents('.acf-field').each(function(){
                var $tab = $(this).prevAll('[data-type="tab"]').first();
                if($tab.length){
                    var tab_data_key = $tab.attr('data-key');
                    $tab.prevAll('.acf-tab-wrap').find('a[data-key="' + tab_data_key + '"]').click();
                }
            });
        }
    
        return json;
    });
  • You can use JS for this.

    Here is how you can add JS:
    https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    And there is a JS filter for changing settings of tinymce (wysiwyg editor) before it’s initialized.
    https://www.advancedcustomfields.com/resources/javascript-api/#filters-wysiwyg_tinymce_settings

    And here is the final code. Just change ‘field_abcd123456’ to whatever is the key of your field.

    
    add_action('acf/input/admin_footer', function(){
        ?>
        <script>
    
            acf.addFilter('wysiwyg_tinymce_settings', function( mceInit, id, field ){
                if(field.get('key') !== 'field_abcd123456'){
                    return mceInit;
                }
                mceInit.block_formats = 'Paragraph=p;Heading 4=h4';
                return mceInit;
            });
    
        </script>
        <?php
    });
    
Viewing 4 posts - 1 through 4 (of 4 total)