Skip to content

Commit

Permalink
Merge pull request #17 from saicheck2233/new_ValidateRadioButton
Browse files Browse the repository at this point in the history
Enhancement: Add validation support for radio button
  • Loading branch information
saicheck2233 authored Jul 11, 2023
2 parents 7453938 + 11b181a commit 95805e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/js/brutusin-json-forms-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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");
Expand Down
14 changes: 14 additions & 0 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 95805e3

Please sign in to comment.