Copying Group field entries from another custom post type?

Support MB Group Copying Group field entries from another custom post type?Resolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30532
    hannuhhannuh
    Participant

    Hi!

    I have custom post type: 'events'. Inside events I have defined a metabox group (clone: true) for 'form fields'. Form fields is used to define event registration form input fields for each event.

    I have created another custom post type: 'forms'. Forms I want to use to define form field templates. Forms have also metabox group (clone: true) to define 'form fields'. Idea is that admin user can define form templates and the re-use these ready made templates on 'events'.

    Problem: Currently I have defined 'type' => 'post' metabox in 'events' which gets the post_type 'forms'. But with this solution if someone edits the 'forms' post's form fields, form fields will then change in all events where that template is in use. This is not what I want.

    I would want that there is e.g. a "Select template" button on admin side of 'events' post. When clicked pop-up opens and user selects the template from 'forms'. When template is selected and OK clicked from the popup, the form fields from template are copied to the 'events' metabox group 'form fields' entries.

    My question: Is it possible and how do I add in JavaScript Group field clones?

    #30538
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Meta Box doesn't support populating field values with JavaScript like that. With a group field cloneable, it is very complicated to accomplish. You can try to set the field value after updating the post (reload the page) by using the helper function rwmb_set_meta().

    I hope that helps.

    #30551
    hannuhhannuh
    Participant

    Thanks! Indeed that is one solution for this. One problem seems to be that as I have Block editor enabled, the custom post edit screen is not fully refreshing after clicking "Update" button, thus the newly copy pasted group values are not visible, it is bit ugly hack to manually need to hit Refresh for browser. Is there any solution for this? Thanks!

    #30568
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The Block editor does not support reloading the page after updating the post. You can use the Classic editor instead of the Block editor.

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