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

时间:2017-06-22 13:00:18

标签: php html prestashop prestashop-1.5 prestashop-1.7

我想显示或隐藏一些字段,根据我后台表单中的下拉列表的更改,这是一个非常html表单,它的prestashop backoffice帮助程序类形式

因为如果在第一个下拉列表列表中选择类型是“类别”,则它应显示(选择类别)的下拉列表,并应隐藏其他两个下拉列表(选择产品,选择要约)。

$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'
        )
    );

所以下拉字段应根据第一个下拉选项显示 任何想法请分享。

1 个答案:

答案 0 :(得分:0)

使用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);
}
}