Skip to content

Commit 50bf052

Browse files
committed
fix nested required properties #56
1 parent a454f6b commit 50bf052

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

dist/js/brutusin-json-forms.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ if (typeof brutusin === "undefined") {
159159
/// TODO change the handler for when there is a 'media'
160160
/// specifier so it becomes a file element.
161161
var schemaId = getSchemaId(id);
162+
var parentId = getParentSchemaId(schemaId);
162163
var s = getSchema(schemaId);
164+
var parentSchema = getSchema(parentId);
163165
var input;
164166
if (s.type === "any") {
165167
input = document.createElement("textarea");
@@ -240,7 +242,19 @@ if (typeof brutusin === "undefined") {
240242
var value = getValue(s, input);
241243
if (value === null) {
242244
if (s.required) {
243-
return BrutusinForms.messages["required"];
245+
if (parentSchema && parentSchema.type === "object") {
246+
if (parentSchema.required) {
247+
return BrutusinForms.messages["required"];
248+
} else {
249+
for (var prop in parentObject) {
250+
if (parentObject[prop] !== null) {
251+
return BrutusinForms.messages["required"];
252+
}
253+
}
254+
}
255+
} else {
256+
return BrutusinForms.messages["required"];
257+
}
244258
}
245259
} else {
246260
if (s.pattern && !s.pattern.test(value)) {
@@ -1184,6 +1198,10 @@ if (typeof brutusin === "undefined") {
11841198
return id.replace(/\["[^"]*"\]/g, "[*]").replace(/\[\d*\]/g, "[#]");
11851199
}
11861200

1201+
function getParentSchemaId(id) {
1202+
return id.substring(0, id.lastIndexOf("."));
1203+
}
1204+
11871205
function getSchema(schemaId) {
11881206
return schemaMap[schemaId];
11891207
}

0 commit comments

Comments
 (0)