2014-10-08 115 views
0

我正在研究一个模块,我想知道如何添加多个下拉字段fields_options。Prestashop模块:添加多选择下拉列表

 $this->fields_options = array(
     'Test' => array(
      'title' => $this->l('Test'), 
      'icon' => 'delivery', 
      'fields' => array(
       'IXY_GALLERY_CREATION_OCCASION' => array(
        'title' => $this->l('DropdownList'), 
        'type' => 'select', 
        'multiple' => true , // not working 
        'identifier' => 'value', 
        'list' => array(         
          1 => array('value' => 1, 'name' => $this->l('Test 1 ')), 
          2 => array('value' => 2, 'name' => $this->l('Test 2)'))        
         ) 
       ), 
      ), 
      'description' =>'', 
      'submit' => array('title' => $this->l('Save')) 
     ) 
    ); 
+0

我刚才在这里找到答案相似(或相同)的问题:HTTP: //stackoverflow.com/questions/27731117/prestashop-set-multiple-select-from-the-module-and-get-them-in-the-input请使用此作为指导,以满足形式助手的要求,并建立你的表单正确的方式! – Jamol 2015-11-02 10:03:07

回答

0

我这是怎么上来的我,如果你意思是:

$combo = $this->getAddFieldsValues(); 

    $fields_form = array(
     'form' => array(
      'legend' => array(
       'title' => $this->l('Title'), 
       'icon' => 'icon-cogs' 
      ), 
      'input' => array(
       array(
        'type' => 'select', 
        'lang' => true, 
        'label' => $this->l('Nom'), 
        'name' => 'nom_matiere', 
        'options' => array(
         'query' => $combo[0], 
         'id' => 'id_option', 
         'name' => 'name' 
         ) 
        ), 
       array(
        'type' => 'select', 
        'lang' => true, 
        'label' => $this->l('Nom'), 
        'name' => 'name', 
        'options' => array(
         'query' => $combo[1], 
         'id' => 'id_option', 
         'name' => 'name' 
         ) 
        ), 
       ), 
      ), 
      'submit' => array(
       'title' => $this->l('Save'), 
       'name' => $this->l('updateData'), 
      ) 
     ), 
    ); 
0

答案没有正确..因为它不仅dfined领域在数据库中,也必须捕获和存储在特殊方式的值,在这个例子中我demostrate存储为“1,2,3,6,8”使用单场

的完整代码,所有的步骤都在:这里https://groups.google.com/forum/m/?hl=es#!topic/venenuxsarisari/z8vfPsvFFjk

我把只有最重要的部分..

的诠释,他以前的链接提到,在模型的定义,类和表的SQL添加了一个新的FIEL

这种方法允许存储在数据库中的“1 ,2,3“,所以你可以只使用单个字段来关联多个选定的值,一个更好的可能是使用groupbox但是它的难度很大,请看一下AdminCustomers控制器类的controllers目录中的prestachop,它有一个多选组,它使用存储在单个字段中的关系表事件

然后投入的辅助形式列表阵列中定义了一个选择为:

在开始时不foget到加入该行:

// aqui el truco de guardar el multiselect como una secuencia separada por comas, mejor es serializada pero bueh 
$this->fields_value['id_employee[]'] = explode(',',$obj->id_employee); 

此$ OBJ是所加载先前存储的值时的表示从该对象开始编辑......获取多选字段的存储值,存储为“1,3,4,6”

并且在字段形式的辅助输入列表中定义了选择倍数如:

  array(
       'type' => 'select', 
       'label' => $this->l('Select and employee'), 
       'name' => 'id_employee_tech', 
       'required' => false, 
       'col' => '6', 
       'default_value' => (int)Tools::getValue('id_employee_tech'), 
       'options' => array(
        'query' => Employee::getEmployees(true), // el true es que solo los que estan activos 
        'id' => 'id_employee', 
        'name' => 'firstname', 
        'default' => array(
         'value' => '', 
         'label' => $this->l('ninguno') 
        ) 
       ) 
      ), 

一则覆盖后处理过

public function postProcess() 
{ 
    if (Tools::isSubmit('submitTallerOrden')) 
    { 
     $_POST['id_employee'] = implode(',', Tools::getValue('id_employee')); 
    } 
    parent::postProcess(); 
} 

本作存储在数据库为“1,2,3”