Skip to content

Commit

Permalink
fix nested required properties brutusin#56
Browse files Browse the repository at this point in the history
  • Loading branch information
idelvall committed Feb 7, 2017
1 parent a454f6b commit 50bf052
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
20 changes: 19 additions & 1 deletion dist/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ if (typeof brutusin === "undefined") {
/// TODO change the handler for when there is a 'media'
/// specifier so it becomes a file element.
var schemaId = getSchemaId(id);
var parentId = getParentSchemaId(schemaId);
var s = getSchema(schemaId);
var parentSchema = getSchema(parentId);
var input;
if (s.type === "any") {
input = document.createElement("textarea");
Expand Down Expand Up @@ -240,7 +242,19 @@ if (typeof brutusin === "undefined") {
var value = getValue(s, input);
if (value === null) {
if (s.required) {
return BrutusinForms.messages["required"];
if (parentSchema && parentSchema.type === "object") {
if (parentSchema.required) {
return BrutusinForms.messages["required"];
} else {
for (var prop in parentObject) {
if (parentObject[prop] !== null) {
return BrutusinForms.messages["required"];
}
}
}
} else {
return BrutusinForms.messages["required"];
}
}
} else {
if (s.pattern && !s.pattern.test(value)) {
Expand Down Expand Up @@ -1184,6 +1198,10 @@ if (typeof brutusin === "undefined") {
return id.replace(/\["[^"]*"\]/g, "[*]").replace(/\[\d*\]/g, "[#]");
}

function getParentSchemaId(id) {
return id.substring(0, id.lastIndexOf("."));
}

function getSchema(schemaId) {
return schemaMap[schemaId];
}
Expand Down
Loading

0 comments on commit 50bf052

Please sign in to comment.