在OctoberCMS后端表单中,是否有选择或创建下拉菜单选项的方法?

我想创建一个类别字段,用户可以在其中选择一个已经输入的唯一值或创建自己的唯一类别。在OctoberCMS中有什么方法可以做到这一点?我浏览了表单字段类型并检查了下拉选项。但是找不到任何东西。至少有插件可以做到这一点吗?

sienchou 回答:在OctoberCMS后端表单中,是否有选择或创建下拉菜单选项的方法?

尝试将“数据标签” Select2(下拉)属性添加到字段定义:

category: 
    type: dropdown
    attributes:
        data-tags: true

还定义在相关模型中收集类别值的方法:

public function getCategoryOptions($keyValue = null)
{
    $optList = Category::orderBy('title')->get()->lists('title','title');
    if (!is_null($keyValue))
    {
        $optList = [$keyValue => $keyValue] + $optList;
    }
    return $optList;
}
本文链接:https://www.f2er.com/3145874.html

大家都在问