Skip to content

Commit

Permalink
Fix for issue brutusin#135
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Piela committed Dec 13, 2018
1 parent b83bb78 commit 6bb79af
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ if (typeof brutusin === "undefined") {
option.value = s.enum[i];
appendChild(option, textNode, s);
appendChild(input, option, s);
var assignmentMade = false;
if (value && s.enum[i] === value) {
assignmentMade = true;
selectedIndex = i;
if (!s.required) {
selectedIndex++;
Expand All @@ -203,10 +205,8 @@ if (typeof brutusin === "undefined") {
input.disabled = true;
}
}
if (s.enum.length === 1)
input.selectedIndex = 0;
else
input.selectedIndex = selectedIndex;
input.unableToAssignValue = (value && !assignmentMade);
input.selectedIndex = selectedIndex;
} else {
input = document.createElement("input");
if (s.type === "integer" || s.type === "number") {
Expand Down Expand Up @@ -263,6 +263,10 @@ if (typeof brutusin === "undefined") {
return BrutusinForms.messages["required"];
}
}
if (input.hasOwnProperty("unableToAssignValue") &&
input.unableToAssignValue) {
return BrutusinForms.messages["invalidValue"];
}
} else {
if (s.pattern && !s.pattern.test(value)) {
return BrutusinForms.messages["pattern"].format(s.pattern.source);
Expand Down Expand Up @@ -315,6 +319,11 @@ if (typeof brutusin === "undefined") {
data = value;
}
onDependencyChanged(schemaId, input);

if (input.hasOwnProperty("unableToAssignValue") && value) {
delete input.unableToAssignValue;
BrutusinForms.onValidationSuccess(input);
}
};

if (s.description) {
Expand Down

0 comments on commit 6bb79af

Please sign in to comment.