From 11b181a81f239550e46539e1f54e21108bfc270c Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Sun, 9 Jul 2023 01:12:10 +0800 Subject: [PATCH] enhancement: add validation for radio button --- src/js/brutusin-json-forms-bootstrap.js | 8 ++++++++ src/js/brutusin-json-forms.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/js/brutusin-json-forms-bootstrap.js b/src/js/brutusin-json-forms-bootstrap.js index 46fd20a..c178d00 100644 --- a/src/js/brutusin-json-forms-bootstrap.js +++ b/src/js/brutusin-json-forms-bootstrap.js @@ -212,6 +212,14 @@ if (("undefined" === typeof $ || "undefined" === typeof $.fn || "undefined" === BrutusinForms.onValidationError = function (element, message) { setTimeout(function () { + if (element.tagName === "DIV" && element.childElementCount !== 0) { + for (var i = 0; i < element.childElementCount; i++) { + if (element.childNodes[i].tagName === "INPUT") { + element = element.childNodes[i]; + break; + } + } + } var dataToggle = element.getAttribute("data-toggle"); var dataTrigger = element.getAttribute("data-trigger"); var dataContent = element.getAttribute("data-content"); diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 64b4d34..e4f15ba 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -418,6 +418,20 @@ if (typeof brutusin === "undefined") { input.selectedIndex = 2; } } + + input.getValidationError = function () { + try { + var value = getValue(s, input); + if (value === null) { + if (s.required) { + return BrutusinForms.messages["required"]; + } + } + } catch (error) { + return BrutusinForms.messages["invalidValue"]; + } + }; + input.onchange = function () { if (parentObject) { parentObject[propertyProvider.getValue()] = getValue(s, input);