diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-11-05 18:43:32 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-11-14 20:46:04 +0100 |
commit | 56249c867ee8e6f8ba2dea20a2912428889a010b (patch) | |
tree | 41c1cc9070bbdc5fc093fe783b469c99f58f3a71 /modules | |
parent | fa391e4f96b5d81a86d8be4891b717cd029c4f13 (diff) |
luci-base: cbi.js: enable validation for dropdown fields
Directly attach validation handlers to cbi dropdowns as well, this allows
validating dropdown choices made by the user, similar to how plain select
boxes are handled by the cbi JavaScript.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/cbi.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 662e772bb..00eb53d7b 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -569,7 +569,7 @@ var CBIValidatorPrototype = { return; var input = sibling.querySelector('[data-type]'), - values = input.getAttribute('data-is-list') ? input.value.match(/[^ \t]+/g) : [ input.value ]; + values = input ? (input.getAttribute('data-is-list') ? input.value.match(/[^ \t]+/g) : [ input.value ]) : null; if (values !== null && values.indexOf(ctx.value) !== -1) unique = false; @@ -806,7 +806,9 @@ function cbi_combobox_init(id, values, def, man) { 'class': 'cbi-dropdown', 'display-items': 5, 'optional': obj.getAttribute('data-optional'), - 'placeholder': _('-- Please choose --') + 'placeholder': _('-- Please choose --'), + 'data-type': obj.getAttribute('data-type'), + 'data-optional': obj.getAttribute('data-optional') }, [ E('ul') ]); if (!(obj.value in values) && obj.value.length) { @@ -1134,6 +1136,7 @@ function cbi_validate_field(cbid, optional, type) field.addEventListener("blur", validatorFn); field.addEventListener("keyup", validatorFn); + field.addEventListener("cbi-dropdown-change", validatorFn); if (matchesElem(field, 'select')) { field.addEventListener("change", validatorFn); |