Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add validation support for radio button #17

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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");
Expand Down
23 changes: 23 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 Expand Up @@ -936,6 +950,7 @@ if (typeof brutusin === "undefined") {
return object;
}
}

if (!container) {
return null;
} else {
Expand Down Expand Up @@ -1339,6 +1354,14 @@ if (typeof brutusin === "undefined") {
} else {
value = null;
}
} else if (schema.format === "radio") {
value = null;
for (var i = 0; i < input.childElementCount; i++) {
if (input.childNodes[i].tagName === "INPUT" && input.childNodes[i].checked) {
value = input.childNodes[i].value;
break;
}
}
}
} else if (schema.type === "any") {
if (value) {
Expand Down