Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter philspectrum

    (@philspectrum)

    I have advanced a little, but I still find some problems.

    I’ve created the FormTokenField and now it renders. This is the Javascript code:

    function KeywordsComponent( props ) {
    
        var FormTokenField = wp.components.FormTokenField;
        var tokens = [wp.data.select('core/editor').getEditedPostAttribute('meta')._xbs_meta_keywords_field] ;
    
        return wp.element.createElement( FormTokenField , {
            label: props.label,
            value: tokens,
            onChange: function (content) {
                tokens = content;
                this.value = tokens;
                wp.data.dispatch('core/editor').editPost({ meta: {_xbs_meta_keywords_field: tokens } })
                console.log('El contenido ha cambiado a ', content);
            }
        });
    }
     
    wp.element.render(
        wp.element.createElement(KeywordsComponent, {label: 'Palabras clave'}),
        document.getElementById('xbs-keywords-component')
    );

    But now, when I refresh the page the console output launch this message:

    TypeError: Cannot read property '_xbs_meta_keywords_field' of undefined

Viewing 1 replies (of 1 total)