通过在 prestashop 助手 类 后台表单中选择下拉列表来显示下拉字段

Display dropdown field by selecting dropdown list in prestashop helper classes back-office form

我想根据后台表单中下拉列表的变化来显示或隐藏一些字段,这是 nit html 表单,它的 prestashop 后台助手 类 表单

例如,如果 Select Type 在第一个下拉列表列表中是 "category" 那么它应该显示(Select 类别)的下拉列表并且应该隐藏其他两个下拉列表(Select 产品,Select 报价)。

$this->fields_form = array(
    'legend' => array(
        'title' => $this->l('My Back offie form:'),
        'image' => _PS_ADMIN_IMG_ . 'information.png',
    ),
    'input' => array(
        array(
            'type' => 'select',
            'label' => $this->l('Select Type'),
            'name' => 'slider_type',
            'id' => 'slider_type',
            'options' => array(
                'query' => $slidertypes_option,
                'id' => 'slider_type',
                'name' => 'slider_type'
            )
        ),
        array(
            'type' => 'select',
            'label' => $this->l('Select Category'),
            'name' => 'id_category',
            'id' => 'id_category',
            'options' => array(
                'query' => $category_options,
                'id' => 'id_category',
                'name' => 'category_name'
            )
        ),
        array(
            'type' => 'select',
            'label' => $this->l('Select Offer'),
            'name' => 'id_category',
            'id' => 'id_category',
            'options' => array(
                'query' => $offers_options,
                'id' => 'id_category',
                'name' => 'category_name'
            )
        ),
        array(
            'type' => 'select',
            'label' => $this->l('Select Product'),
            'name' => 'id_product',
            'id' => 'product',

            'options' => array(
                'query' => $products,
                'id' => 'id_product',
                'name' => 'name'
            )
        ),
        //                                                            array(
        //                                                          
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'button'
        ),
        'cancel' => array(
            'title' => $this->l('Cancel'),
            'class' => 'button'
        )
    );

因此下拉字段应根据第一个下拉选择显示 任何想法请分享。

使用 jquery 处理您的表单:

$(document).ready(function(){    
adminControl();
$('#slider_type').change(function(){
    adminControl();
});
});
function adminControl(){
//main value
var type_value = $('#slider_type').val();

var handle1 = $('select#xxxx').parents().eq(2);
var handle2 = $('select#yyyy').parents().eq(2);

switch (type_value) {
    case 'category':
        handle1 .show(500);
        handle2 .hide(500);
        break;
    case 'cms':
        handle1 .hide(500);
        handle2 .show(500);
}
}