1 module uim.bootstrap.bs5.basic.components.forms.controls.select; 2 3 import uim.bootstrap; 4 5 class DBS5InputSelect : DBS5Obj { 6 mixin(H5This!("Select", ["form-control"])); 7 8 mixin(MyContent!("option", "H5Option")); 9 O options(this O)(string[] values, string selected = "", string disabled = "") { 10 foreach(value; values) { 11 if (value == selected) { 12 if (value == disabled) this.option(["selected":"selected", "disabled":"disabled"], value); 13 else this.option(["selected":"selected"], value); 14 } 15 else if (value == disabled) this.option(["disabled":"disabled"], value); 16 else this.option(value); 17 } 18 return cast(O)this; 19 } 20 21 O options(this O)(string[string][] keyValues, string selectedKey = "", string disabledKey = "") { 22 foreach(kv; keyValues) { 23 foreach(k; kv.keys.sort) { 24 if (k == selectedKey) { 25 if (k == disabledKey) this.option(["selected":"selected", "disabled":"disabled"], k); 26 else this.option(["selected":"selected"], k); 27 } 28 else if (k == disabledKey) this.option(["disabled":"disabled"], k); 29 else this.option(["value":k], kv[k]); 30 } 31 } 32 return cast(O)this; 33 } 34 O options(this O)(string[string] values, string selectedKey = "", string disabledKey = "") { 35 foreach(k; values.keys.sort) { 36 if (k == selectedKey) { 37 if (k == disabledKey) this.option(["selected":"selected", "disabled":"disabled"], k); 38 else this.option(["selected":"selected"], k); 39 } 40 else if (k == disabledKey) this.option(["disabled":"disabled"], k); 41 else this.option(["value":k], values[k]); 42 } 43 return cast(O)this; 44 } 45 O options(this O)(string[] values, string[] selected, string[] disabled = null) { 46 foreach(value; values) { 47 if (selected.has(value)) { 48 if (disabled.has(value)) this.option(["selected":"selected", "disabled":"disabled"], value); 49 else this.option(["selected":"selected"], value); 50 } 51 else if (disabled.has(value)) this.option(["disabled":"disabled"], value); 52 else this.option(value); 53 } 54 return cast(O)this; 55 } 56 O options(this O)(string[string] values, string[] selectedKeys, string[] disabledKeys = null) { 57 foreach(k; values.keys.sort) { 58 if (selectedKeys.has(k)) { 59 if (disabledKeys.has(k)) this.option(["selected":"selected", "disabled":"disabled"], k); 60 else this.option(["selected":"selected"], k); 61 } 62 else if (disabledKeys.has(k)) this.option(["disabled":"disabled"], k); 63 else this.option(["value":k], values[k]); 64 } 65 return cast(O)this; 66 } 67 O option(this O)(string value, string key = null, bool selected = false, string disabled = false) { 68 auto result = H5Option; 69 if (selected) result(["selected":"selected"]); 70 if (disabled) result(["disabled":"disabled"]); 71 if (key.length == 0) result(["value":k]); 72 this(result(value)); 73 return cast(O)this; 74 } 75 } 76 mixin(H5Calls!("BS5InputSelect")); 77 78 unittest { 79 80 81 }