From 56249c867ee8e6f8ba2dea20a2912428889a010b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 5 Nov 2018 18:43:32 +0100 Subject: [PATCH] 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 --- modules/luci-base/htdocs/luci-static/resources/cbi.js | 7 +++++-- 1 file 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 662e772bb1..00eb53d7ba 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); -- 2.30.2