Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create dynamic fields in visual composer?

I am creating visual composer plugin for price table. I want to add dynamic textfield so user become able to add multiple text fields for item list as want. For now it's showing only one text field but user should able to add multiple fields.

 array (
    "type"          =>  "textfield",
    "heading"       =>  __( 'List Items', 'pt-vc' ),
    "param_name"    =>  "price_list",
    "description"   =>  __( 'Write the list item that you offer', 'pt-vc' ),
    "group"         =>  'List Item',
 ),
like image 269
Nasir Avatar asked Aug 13 '16 03:08

Nasir


2 Answers

You can use param_group. Here is the code example.

'params'=> array (
   array(
     'type' => 'param_group',
      'value' => '',
      'heading' =>  __( 'List Items', 'pt-vc' ),
      'param_name' => 'price_list',
       // Note params is mapped inside param-group:
      'params' => array(
          array(
             'type' => 'textfield',
             'value' => '',
             'heading' => __( 'List Items', 'pt-vc' ),
             'param_name' => 'list_itmes',
         )
      )
   )
);

I think answer may be late but help others.

like image 150
Nand Lal Avatar answered Nov 04 '22 09:11

Nand Lal


You may use param_group for that. It's not mentioned in the documentation but you may find it "How To's" https://kb.wpbakery.com/docs/developers-how-tos/use-param-group-in-elements/

Code snippet from link (in case link expires again):

vc_map(
   array(
      'base' => 'your_shortcode',
      'params' => array(
         array(
         'type' => 'textfield',
         'value' => '',
         'heading' => 'Title',
         'param_name' => 'simple_textfield',
         ),
         // params group
         array(
            'type' => 'param_group',
            'value' => '',
            'param_name' => 'titles',
            // Note params is mapped inside param-group:
            'params' => array(
               array(
               'type' => 'textfield',
               'value' => '',
               'heading' => 'Enter your title(multiple field)',
               'param_name' => 'title',
               )
            )
         )
      )
   )
)
like image 28
skyddy Avatar answered Nov 04 '22 09:11

skyddy