How to add new clone to a cloneable text list custom field with three inputs

Support MB Custom Table How to add new clone to a cloneable text list custom field with three inputsResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #39698
    mossmanmossman
    Participant

    I am trying to add a new clone (or element) to a cloneable text list with three inputs with the custom table API. This is the text field:
    image1

    The desired result is this, add a new clone with the values in all inputs:
    image2

    I am using this code but does not work. I think that I am not building correctly the "$data" array:

    function add_product_register() {
        $exists = false;
    
        $table_name = "cmp_customfields";
        $post_id = 17;
    
        $exists = \MetaBox\CustomTable\API::exists($post_id, $table_name);
    
         if ($exists){
             $data = [
                 'id_of_text_list' => ["date2", "price2", "name2"],
             ];
             \MetaBox\CustomTable\API::add($post_id, $table_name, $data);
         }
    }

    Thank you in advance!

    #39765
    PeterPeter
    Moderator

    Hello,

    You can use the code below to update the cloneable text list value to the custom table

    add_action( 'save_post', function( $post_id ) {
        $data = [ 
            'id_of_text_list' => [ 
                ['date1', 'name1', 'price1'],
                ['date2', 'name2', 'price2'],
                ['date3', 'name3', 'price3'],
            ]
        ];
        \MetaBox\CustomTable\API::update( $post_id, "cmp_customfields", $data );
    } );
    
    #39767
    mossmanmossman
    Participant

    Hello Peter,
    Thank you for your help. I want to add only one row to the cloneable text list, not update the whole cloneable text list.

    Is it possible do that with the \MetaBox\CustomTable\API::add() function?

    Thank you!

    #39788
    PeterPeter
    Moderator

    Hello,

    It is not possible, you have to update the whole text list data in the database.

    #39806
    mossmanmossman
    Participant

    Hello Peter,
    Ok, this is a huge limitation. In fact, then Metabox is not the right plugin for me. Have you any ETA for the implementation of this feature?

    Thank you

    #39833
    PeterPeter
    Moderator

    Hello,

    Sorry, it is not a feature request yet so I do not have ETA for this. I will inform the development team to consider supporting this feature in future updates.

    #39864
    mossmanmossman
    Participant

    thank you Peter!

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