PrestaShop自定义模块中添加带搜索功能的产品选择框
给PrestaShop自定义模块的产品选择框添加搜索功能
要给你的Bootstrap Select选择框启用实时搜索,只需要在表单字段的配置数组中添加data属性配置即可。PrestaShop的表单生成器会自动将data数组中的键值对转换为对应的HTML data-*属性。
修改后的代码
$fields_form = [ 'form' => [ 'legend' => [ 'title' => $this->trans('Settings', [], 'Admin.Global'), 'icon' => 'icon-cogs', ], 'description' => $this->trans('Add products to your homepage', [], 'Modules.Featuredproducts.Admin'), 'input' => [ [ 'type' => 'select', 'label' => $this->l('Select a Product'), 'name' => 'id_product', 'required' => false, 'col' => '8', 'class' => 'selectpicker', 'bootstrap' => true, // 添加这一行启用实时搜索 'data' => ['live-search' => 'true'], 'options' => [ 'query' => Product::getProducts($this->context->language->id, 0, 0, "id_product", "desc"), 'id' => 'id_product', 'name' => 'name', 'default' => [ 'value' => '', 'label' => $this->l('--') ] ] ] ], 'submit' => [ 'title' => $this->trans('Save', [], 'Admin.Actions'), ], ], ];
补充说明
- 如果需要同时选择4个产品,可以在字段配置中添加
'multiple' => true,让选择框支持多选,配合实时搜索能进一步提升操作效率。 - 确认后台已正确加载Bootstrap Select的JS和CSS文件,PrestaShop默认后台通常已集成,但自定义主题可能需要额外检查。
内容的提问来源于stack exchange,提问作者MPN7
相关产品推荐
相关产品推荐

