Support » Developing with WordPress » WordPress gutenberg block – jquery generated content not saved

  • I am new to WordPress Gutenberg blocks. I created a gallery plugin and I want a user to be able to insert gallery shortcode by simply choosing the desired gallery from a popup window. I use jQuery text() function to inject shortcodes from the popup window with success but the content will not be saved. However, when I type in some text everything works fine.

    Here is my Gutenberg js:

    var el = wp.element.createElement,
    registerBlockType = wp.blocks.registerBlockType,
    RichText = wp.editor.RichText,
    blockStyle = { backgroundColor: '#0000cc', color: '#fff', padding: '1%', margin: '1%', border: 'none', boxShadow: '5px 5px 5px #000', cursor: 'pointer' };
    
    registerBlockType( 'prtxgal/block', {
        title: 'Protex gallery',
    
        icon: 'images-alt',
    
        category: 'common',
    
        attributes: {
            content: {
                type: 'string',
                source: 'html',
                selector: 'div',
            }
        },
    
        edit: function(props) {
            var content = props.attributes.content;
    
            function onChangeContent( newContent ) {
                props.setAttributes( { content: newContent } );
            }
    
            return[ el(
                'button', { className: 'button add_prtxgal', /*style: blockStyle*/}, 'Choose gallery'
                ),
                el (RichText,
                {
                    tagName: 'div',
                    className: props.className,
                    onChange: onChangeContent,
                    value: content,
                }
                ),
            ];
        },
    
        save: function(props) {
            var content = props.attributes.content;
    
            return el( RichText.Content, {
                tagName: 'div',
                className: props.className,
                value: content
            });
        },
    });
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress gutenberg block – jquery generated content not saved’ is closed to new replies.