2016-10-16 35 views
0

我正在開發一個海狸生成器擴展,每件事情都很好,但問題是,我想給一些選擇能夠選擇給客戶端,以便他/她可以選擇他們各自的選項,我們可以提供功能,根據他們的選擇。製作海狸生成器模塊設置選擇了能?

例如,我想給出2個選項。選項一,選擇你的文章類型?選項是「發佈」,「自定義帖子」...現在,如果他/她選擇「發佈」我想顯示一些選項只發布相關,但如果他/她選擇「自定義帖子」我想顯示選項相關的自定義帖子。我在視覺作曲家中做過這件事,但迄今爲止無法在海狸製造商那裏做。

下面是一些我的代碼:

'sections'  => array(// Tab Sections 
     'general'  => array(// Section 
      'title'   => __('Section Title', 'fl-builder'), // Section Title 
      'fields'  => array(// Section Fields 
       'select_field' => array(
        'type'   => 'select', 
        'label'   => __('Show Filter or Not?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'no_of_posts' => array(
        'type'   => 'my-custom-field', 
        'label'   => __('Provide your desired number of Posts', 'fl-builder'), 
        'default'  => '8' 
       ), 
       'no_of_cols' => array(
        'type'   => 'select', 
        'label'   => __('Provide your desired number of Cols', 'fl-builder'), 
        'default'  => 'option-2', 
        'options'  => array(
         'option-1'  => __('2', 'fl-builder'), 
         'option-2'  => __('3', 'fl-builder'), 
         'option-3'  => __('4', 'fl-builder'), 
         'option-4'  => __('6', 'fl-builder') 
        ) 
       ), 
       'show_overlay' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to Show Overlay?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'show_lightbox' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to Open Image in lightbox?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'show_lightbox_link' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to show Link Icon in Lightbox?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'show_title' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to show Post Title?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'show_title_link' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to use Link in Post Title?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'show_content' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to show Post Content?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 
       'show_link' => array(
        'type'   => 'select', 
        'label'   => __('Do You Want to show Post Link?', 'fl-builder'), 
        'default'  => 'option-1', 
        'options'  => array(
         'option-1'  => __('Yes', 'fl-builder'), 
         'option-2'  => __('No', 'fl-builder') 
        ) 
       ), 

的一點是再簡單不過:我想選擇一些其他相關的選項時,只顯示我的選擇。

例如,如果用戶選擇選項「後」,那麼這應該做

'no_of_cols' => array(
       'type'   => 'select', 
       'label'   => __('Provide your desired number of Cols', 'fl-builder'), 
       'default'  => 'option-2', 
       'options'  => array(
        'option-1'  => __('2', 'fl-builder'), 
        'option-2'  => __('3', 'fl-builder'), 
        'option-3'  => __('4', 'fl-builder'), 
        'option-4'  => __('6', 'fl-builder') 
       ) 
      ), 

意味着我要顯示的選擇選項只有在後選擇等希望我明確傳達我的問題。

回答

0

我可能爲時太晚了!

但你只需要使用'切換'。

'select_field' => array(
    'type'   => 'select', 
    'label'   => __('Show Filter or Not?', 'fl-builder'), 
    'default'  => 'option-1', 
    'options'  => array(
    'option-1'  => __('Yes', 'fl-builder'), 
    'option-2'  => __('No', 'fl-builder') 
), 
    'toggle' => array(
    'option-1' = array(
     'fields' => array('another_field') 
    ) 
) 
), 
'another_field' => array() 
+0

是的,那很簡單,非常感謝 – laraib