Custom Fields
Re-Envisioned
Support General Proper way to clone a custom field

This topic contains 3 replies, has 2 voices, and was last updated by  Bruno Faúndez Valenzuela 7 hours, 35 minutes ago.

  • Creator
    Topic
  • #14999
    Resolved
    Bruno Faúndez Valenzuela
    Participant

    Hi. I created a Custom Field Type to add service IDs to Hotels (which is a CPT). I defined the field type as: tb-service-id. Then I add this field to the corresponding metabox. I’ve set:

    'clone' => true

    and the button to clone the field appears, but the field is generated with the same ID as the other one:

    _hotel_tb_service_id[0]

    In the html mehod of the Custom Field Type I create a select and set the ID to the variable: $field[‘id’] which gives the value: ‘_hotel_tb_service_id[0]’.

    Any help would be much appreciated

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #15009

    Anh Tran
    Keymaster

    Hi Bruno,

    Please try to set a custom CSS class for the inputs which starts with rwmb. See here to understand how the clone works.

    #15032

    Thank you so much! It worked perfectly!
    It would be good to see a comment about the relation of the css class and the “cloneability” of the field in the documentation of the RWMB_Field Class.

    Have a great day 🙂

    #16161

    Hi. I’m getting some weird behaviour related to this. My custom field has some selects that are used to filter asyncronously a list with the option for the field. The custom field looks like this:

    [Service Type]
    [Service Region]
    [Service]

    All of those three inputs are selects but only the last one is the value that should be stored. It’s wrapped as a vue.js app and when you select one of the [Service Type] or [Service Region] options, the [Service] select is populated with data.

    The [Service] select has the class rwmb-vueselect so it can be detected by the plugin.

    With a single input it works well, but when I clone it, the data of the first input stores the [Service Region] selection of the second field and the second field stores it’s proper data from its [Service]. Is there any way to explicitly say which fields should be stored?

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.