Cloning a Gutenberg block group containing custom RWMB_Field

Support MB Blocks Cloning a Gutenberg block group containing custom RWMB_FieldResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29299
    Jean-Michel JunodJean-Michel Junod
    Participant

    After trying to clone a group containing the custom field type described on page:
    https://metabox.io/page/2/?post_type=docs&p=390, I noticed that the name of the cloned input fields was not correctly updated. Looking at the clone.js function, it looks that the input has to have a class beginning with "rwmb" or the name won't be properly indexed (it would keep the index of the originally cloned field).
    I think it would worth a note on the example page to explain this, it took me 4 hours to understand why the field was not cloned properly (values were not saved hence indexes were wrong).

    So in short if you want to create a custom RWMB_Field that you want to use in a clonable Gutenberg block, you apparently need to add a class beginning with "rwmb" on the field, like:

    static public function html( $meta, $field )
    {
        return sprintf(
            '<input type="tel" name="%s" id="%s" value="%s" pattern="d{3}-d{4}" <strong>class="rwmb-tel"</strong>>',
            $field['field_name'],
            $field['id'],
            $meta
        );
    }
    #29340
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for your feedback.

    We've written a note about the cloneable custom field type on the documentation before, please find it here https://docs.metabox.io/custom-field-type/#notes

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.