field-select
field 個外殼包住一個原生 select。超過十個選項嗰陣,個 select 就會開 select.js 嘅可篩選組合框;但表單提交嘅仲係嗰個原生 select。
三個選項:原生 select
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="sel_few" >角色</label >
<select rst-input id ="sel_few" name ="sel_few" >
<option value ="admin" selected >管理員</option >
<option value ="editor" >編輯</option >
<option value ="member" >成員</option >
</select >
</div >
將呢段放入 <section rst-box><form rst-form> 入面。
{{ template "field-select" dict
"ID" "sel_few"
"Name" "sel_few"
"Label" "角色"
"Options" (list
(dict "Label" "管理員" "Selected" true "Value" "admin" )
(dict "Label" "編輯" "Value" "editor" )
(dict "Label" "成員" "Value" "member" ))}}
十二個選項:可篩選嘅組合框
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="sel_many" >城市</label >
<select rst-input id ="sel_many" name ="sel_many" data-rst-select data-rst-select-filter ="輸入嚟篩選" data-rst-select-results ="{n} 個結果" data-rst-select-result-one ="1 個結果" data-rst-select-no-matches ="冇相符嘅結果" aria-describedby ="sel_many-help" >
<option value ="dublin" selected >都柏林</option >
<option value ="lisbon" >里斯本</option >
<option value ="madrid" >馬德里</option >
<option value ="berlin" >柏林</option >
<option value ="rome" >羅馬</option >
<option value ="athens" >雅典</option >
<option value ="helsinki" >赫爾辛基</option >
<option value ="reykjavík" >雷克雅未克</option >
<option value ="warsaw" >華沙</option >
<option value ="zagreb" >薩格勒布</option >
<option value ="tallinn" >塔林</option >
<option value ="valletta" >華列他</option >
</select >
<p rst-field-help id ="sel_many-help" >開始打字就可以篩選。</p >
</div >
將呢段放入 <section rst-box><form rst-form> 入面。
{{ template "field-select" dict
"ID" "sel_many"
"Name" "sel_many"
"Label" "城市"
"Options" (list
(dict "Label" "都柏林" "Selected" true "Value" "dublin" )
(dict "Label" "里斯本" "Value" "lisbon" )
(dict "Label" "馬德里" "Value" "madrid" )
(dict "Label" "柏林" "Value" "berlin" )
(dict "Label" "羅馬" "Value" "rome" )
(dict "Label" "雅典" "Value" "athens" )
(dict "Label" "赫爾辛基" "Value" "helsinki" )
(dict "Label" "雷克雅未克" "Value" "reykjavík" )
(dict "Label" "華沙" "Value" "warsaw" )
(dict "Label" "薩格勒布" "Value" "zagreb" )
(dict "Label" "塔林" "Value" "tallinn" )
(dict "Label" "華列他" "Value" "valletta" ))
"Help" "開始打字就可以篩選。" }}
超過十個選項,片段就會開 select.js;唔夠十個就唔會:喺得幾項嘢入面搵嘢只係擺設,唔係幫忙。
十二個選項,Plain:明確唔要嗰個加強
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="sel_plain" >城市</label >
<select rst-input id ="sel_plain" name ="sel_plain" >
<option value ="dublin" selected >都柏林</option >
<option value ="lisbon" >里斯本</option >
<option value ="madrid" >馬德里</option >
<option value ="berlin" >柏林</option >
<option value ="rome" >羅馬</option >
<option value ="athens" >雅典</option >
<option value ="helsinki" >赫爾辛基</option >
<option value ="reykjavík" >雷克雅未克</option >
<option value ="warsaw" >華沙</option >
<option value ="zagreb" >薩格勒布</option >
<option value ="tallinn" >塔林</option >
<option value ="valletta" >華列他</option >
</select >
</div >
將呢段放入 <section rst-box><form rst-form> 入面。
{{ template "field-select" dict
"ID" "sel_plain"
"Name" "sel_plain"
"Label" "城市"
"Options" (list
(dict "Label" "都柏林" "Selected" true "Value" "dublin" )
(dict "Label" "里斯本" "Value" "lisbon" )
(dict "Label" "馬德里" "Value" "madrid" )
(dict "Label" "柏林" "Value" "berlin" )
(dict "Label" "羅馬" "Value" "rome" )
(dict "Label" "雅典" "Value" "athens" )
(dict "Label" "赫爾辛基" "Value" "helsinki" )
(dict "Label" "雷克雅未克" "Value" "reykjavík" )
(dict "Label" "華沙" "Value" "warsaw" )
(dict "Label" "薩格勒布" "Value" "zagreb" )
(dict "Label" "塔林" "Value" "tallinn" )
(dict "Label" "華列他" "Value" "valletta" ))
"Plain" true }}
必填,仲有錯誤
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="sel_error" >角色</label >
<select rst-input id ="sel_error" name ="sel_error" required aria-invalid ="true" aria-describedby ="sel_error-error" >
<option value ="admin" selected >管理員</option >
<option value ="editor" >編輯</option >
<option value ="member" >成員</option >
</select >
<p rst-field-error id ="sel_error-error" role ="alert" >幫呢個人揀個角色。</p >
</div >
將呢段放入 <section rst-box><form rst-form> 入面。
{{ template "field-select" dict
"ID" "sel_error"
"Name" "sel_error"
"Label" "角色"
"Options" (list
(dict "Label" "管理員" "Selected" true "Value" "admin" )
(dict "Label" "編輯" "Value" "editor" )
(dict "Label" "成員" "Value" "member" ))
"Required" true
"Error" "幫呢個人揀個角色。" }}
手寫嘅,有 optgroup 分組
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="sel_grouped" >地區</label >
<select rst-input id ="sel_grouped" name ="sel_grouped" data-rst-select data-rst-select-filter ="輸入嚟篩選" data-rst-select-results ="{n} 個結果" data-rst-select-result-one ="1 個結果" data-rst-select-no-matches ="冇相符嘅結果" >
<optgroup label ="歐洲" >
<option value ="dublin" selected >都柏林</option >
<option value ="lisbon" >里斯本</option >
<option value ="warsaw" >華沙</option >
</optgroup >
<optgroup label ="美洲" >
<option value ="montreal" >滿地可</option >
<option value ="lima" >利馬</option >
<option value ="austin" >奧斯汀</option >
</optgroup >
<optgroup label ="亞洲" >
<option value ="osaka" >大阪</option >
<option value ="hanoi" >河內</option >
<option value ="dhaka" >達卡</option >
</optgroup >
<optgroup label ="非洲" >
<option value ="accra" >阿克拉</option >
<option value ="nairobi" >奈洛比</option >
<option value ="tunis" >突尼斯</option >
</optgroup >
</select >
</div >
呢度嘅 Options 係一個平面清單,所以分咗組嘅選項要應用自己寫成標記。select.js 會將啲組畫出嚟而唔係掉咗佢;手寫嘅 select 亦可以用 data-rst-select="false" 徹底唔要呢個加強。