Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichText: Saving Meta #23304

Closed
adamrob-me opened this issue Jun 19, 2020 · 6 comments
Closed

RichText: Saving Meta #23304

adamrob-me opened this issue Jun 19, 2020 · 6 comments
Labels
Needs Testing Needs further testing to be confirmed. [Package] Rich text /packages/rich-text [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed.

Comments

@adamrob-me
Copy link

Describe the bug
I want to save some HTML to my meta data using the rich text component.

  • If the key does not exist, the rich text will create and save the key and value no issues.
  • It will save edits as required; no issues as long as the page has not been re-loaded.
  • When the page is re-loaded, it no longer saves the modified value. I have to delete the meta for it to be re-created and saved correctly.

To reproduce

Steps to reproduce the behavior:

  1. Create new page
  2. Add new block
  3. Add text, update page, notice how the meta data has been created and saved.
  4. Make an edit, update page, notice how the meta data has been updated correctly.
  5. Refresh the page. Make an edit to the block and update page. Notice how the meta is NOT updated anymore.
  6. Delete Meta, and reproduce steps above.

My code to register the meta key:

public function register_meta(){
    // register custom meta tag field
    $sts=register_post_meta( "page"
		, $this->get_meta_key()
		, array(
			"show_in_rest" => true,
			"single" => true,
			"type" => "string",
			"sanitize_callback" => "meta_box_sanitize"
			)
		);
	}

my JS for the rich text control:

( function( wp ) {
const { registerBlockType } = wp.blocks;
const { RichText } = wp.blockEditor;

registerBlockType( 'adamrob/page-intro', {
    title: 'Page Intro',
    icon: 'welcome-view-site',
    category: 'formatting',
    keywords: [],
    attributes: {
        content: {
            type: 'string',
            source: 'meta',
            meta: 'adamrob_iceberg_intro_meta_key',
        },
    },

    edit: function( props ) {
        var setAttributes = props.setAttributes;
        /* define functions */
        function onChangeIntro( content ) {
            setAttributes( { content: content } );
        }
        return wp.element.createElement( wp.blockEditor.RichText, {
                    format: 'string',
                    tagName: 'p',
                    //className: 'event-host',
                    label: 'Meta Block Field',
                    value: props.attributes.content,
                    onChange: onChangeIntro,
                    //formattingControls: [ 'bold', 'italic' ], // Allow the content to be made bold or italic, but do not allow other formatting options
                } );
    },
    
    save: function( props ) {
        return null;
    }
} );
} )( window.wp );

Expected behavior
Meta data to always save.

Editor version (please complete the following information):

  • WordPress version: 5.4.2
  • Gutenberg plugin version: 8.3.0

Desktop (please complete the following information):

  • Browser: Chrome
@talldan talldan added the [Status] Needs More Info Follow-up required in order to be actionable. label Aug 14, 2020
@talldan
Copy link
Contributor

talldan commented Aug 14, 2020

@adamrob-me Just wondering if this is a bug report or a help request?

The phrasing makes it sound like a help request, but the bug report template is being used.

@adamrob-me
Copy link
Author

I believe it is a bug...

@youknowriad youknowriad added Needs Testing Needs further testing to be confirmed. and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Sep 15, 2020
@leclaeli
Copy link

I am experiencing the same issue as @adamrob-me. It also happens when trying to use a RichText component to store post meta in a block as demonstrated in the tutorial: https://developer.wordpress.org/block-editor/tutorials/metabox/meta-block-1-intro/. Works fine initially, but when you reload the page and make an edit, then save, the value goes back to what was stored in postmeta on the initial page load.

@skorasaurus skorasaurus added the [Package] Rich text /packages/rich-text label Feb 3, 2021
@adamrob-me
Copy link
Author

Its been over 6 months since I raised this issue - and it is still there....

@torounit
Copy link
Member

torounit commented Jul 6, 2021

@adamrob-me

Is the Custom Fields panel enabled?

If that panel is enabled, there is a known issue where updates from the block will be overwritten by data in the panel. #23078
The current workaround is to disable the custom fields panel.

If the custom fields panel is enabled, we would like to close this ticket and merge it with #23078.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 25, 2022
@torounit
Copy link
Member

I would like to close this issue as I believe it is the same as #23078 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed. [Package] Rich text /packages/rich-text [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed.
Projects
None yet
Development

No branches or pull requests

6 participants