Custom Fields
Re-Envisioned
Support MB Blocks Cloning a Gutenberg block group containing custom RWMB_Field

  • Creator
    Topic
  • #29299
    Resolved PASCAL Hämmerli
    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
        );
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.