Skip to content

Commit 9432d82

Browse files
committed
Add check for schema property
Fixes angular-schema-form#558 Add check for schema property to prevent form generation failures when a checkbox is explicitly defined by a developer (and therefore does not have a schema property) by @vinceis1337 in angular-schema-form#663
1 parent 179a25f commit 9432d82

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

dist/json-schema-form-core.js

+9-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-schema-form-core.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-schema-form-core",
3-
"version": "1.0.0-alpha.2",
3+
"version": "1.0.0-alpha.3",
44
"description": "JSON-Schema and JSON-UI-Schema utilities for form generation.",
55
"main": "dist/json-schema-form-core.js",
66
"scripts": {

src/lib/merge.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,22 @@ export function merge(lookup, form, ignore, options, readonly, asyncTemplates) {
111111

112112
// Special case: checkbox
113113
// Since have to ternary state we need a default
114-
if (obj.type === 'checkbox' && obj.schema['default'] === undefined) {
115-
obj.schema['default'] = false;
114+
if (obj.type === 'checkbox') {
115+
// Check for schema property, as the checkbox may be part of the explicitly defined form
116+
if (obj.schema === undefined) {
117+
obj.schema = { default: false };
118+
}
119+
else if (obj.schema['default'] === undefined) {
120+
obj.schema['default'] = false;
121+
};
116122
};
117123

118124
// Special case: template type with tempplateUrl that's needs to be loaded before rendering
119125
// TODO: this is not a clean solution. Maybe something cleaner can be made when $ref support
120126
// is introduced since we need to go async then anyway
121127
if (asyncTemplates && obj.type === 'template' && !obj.template && obj.templateUrl) {
122128
asyncTemplates.push(obj);
123-
}
129+
};
124130

125131
return obj;
126132
});

0 commit comments

Comments
 (0)