0

I am looking to edit an existing block to add inspector controls that save as meta data. I have been beating my head trying to find how to save the data. The following code adds a text field to the inspector system . I can add the field but for some reason the field does not save. I can not for the life of me figure it out.

var el = wp.element.createElement,
    Fragment = wp.element.Fragment
    registerBlockType = wp.blocks.registerBlockType,
    RichText = wp.editor.RichText,
    BlockControls = wp.editor.BlockControls,
    AlignmentToolbar = wp.editor.AlignmentToolbar,
    Fields = wp.components;

var withInspectorControlsEdit = wp.compose.createHigherOrderComponent( function( BlockEdit ) {
    return function( props ) {
        return el(
            wp.element.Fragment,
            {},
            el( BlockEdit, props ),
            el(
                wp.editor.InspectorControls,
                {},
                el(
                    Fields.PanelBody,
                    {},
                    el(
                        Fields.TextControl,
                        {
                            label: 'Test Field',
                            value: props.attributes.testField,
                            onChange: function(e){
                                props.setAttributes({ testField: e });
                            }
                        }
                    )
                )   
            )
        )
    };
}, 'withInspectorControlsEdit' );
wp.hooks.addFilter( 'editor.BlockEdit', 'acf/accordion', withInspectorControlsEdit );
  • This isn't off topic, but, you really should open an issue over on the gutenberg github, it's the best place to ask these kinds of questions in the run up to the 5.0 release ( I asked numerous gutenberg leads and they said so ) – Tom J Nowell Oct 20 '18 at 21:14
0

Have you set your attribute (testField) up as meta?

attributes: { testField: { type: 'string', source: 'meta', meta: 'testField' }, },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.