addSelect("name值", "标题", "提示", "选项" [, "默认值", "额外属性", "额外css类"])
标识符:select
版本 | 新增功能 |
---|---|
1.0.7 | 支持自定义placeholder |
参数 | 含义 | 类型 |
---|---|---|
name | name值 | string |
title | 标题 | string |
tips | 提示 | string |
options | 选项 | array |
default | 默认值 | string |
extra_attr | 额外属性 | string |
extra_class | 额外css类 | string |
下拉菜单的用法和复选、单选类似。
简单的例子
return ZBuilder::make("form")
->addSelect("city", "选择城市", "", ["gz" => "广州", "sz" => "深圳", "sh" => "上海"])
->fetch();
默认值
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->setPageTitle("添加")
->addSelect("city", "选择城市", "请选择城市", $list_city, "gz")
->fetch();
多选
下拉菜单也可以设置为多选,只要添加额外属性为“multiple”即可。
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->setPageTitle("添加")
->addSelect("city", "选择城市", "请选择城市", $list_city, "", "multiple")
->fetch();
多选的话,发送到服务器的则为数组形式。
默认值可设置多个,值之间用逗号隔开。
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->setPageTitle("添加")
->addSelect("city", "选择城市", "请选择城市", $list_city, "gz,sh", "multiple")
->fetch();
自定义placeholder
从1.0.7版本开始,可以自定义表单项的placeholder,只需在title后面添加“[:提示文字]
”,如:
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->setPageTitle("添加")
->addSelect("city", "选择城市[:请选择一个城市]", "请选择城市", $list_city, "gz,sh", "multiple")
->fetch();