Skip to content

Commit 2d7fb3a

Browse files
committed
Checkboxes implies a default of false
Which means every time you have a checkbox in the form it will automatically act as if you put "default": false in the schema.
1 parent f9bb86c commit 2d7fb3a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/directives/decorators/bootstrap/checkbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="checkbox"
44
sf-changed="form"
55
ng-model="$$value$$"
6-
schema-validate="form"
6+
schema-validate="form">
77
<span ng-bind-html="form.title"></span>
88
</label>
99

src/services/schema-form.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ angular.module('schemaForm').provider('schemaForm',['sfPathProvider', function(s
4747
if (schema.title) f.title = schema.title;
4848
if (schema.description) f.description = schema.description;
4949
if (options.required === true || schema.required === true) f.required = true;
50-
if (schema.default !== undefined) f.default = schema.default;
5150
if (schema.maxLength) f.maxlength = schema.maxLength;
5251
if (schema.minLength) f.minlength = schema.maxLength;
5352
if (schema.readOnly || schema.readonly) f.readonly = schema.readOnly || schema.readonly;
@@ -303,23 +302,29 @@ angular.module('schemaForm').provider('schemaForm',['sfPathProvider', function(s
303302

304303
//if its has tabs, merge them also!
305304
if (obj.tabs) {
306-
angular.forEach(obj.tabs,function(tab){
307-
tab.items = service.merge(schema,tab.items,ignore);
305+
angular.forEach(obj.tabs, function(tab) {
306+
tab.items = service.merge(schema, tab.items, ignore);
308307
});
309308
}
310309

311310
//extend with std form from schema.
312311
if (obj.key) {
313-
if(typeof obj.key == 'string') {
312+
if (typeof obj.key === 'string') {
314313
obj.key = sfPathProvider.parse(obj.key);
315314
}
316315

317316
var str = sfPathProvider.stringify(obj.key);
318-
if(lookup[str]){
319-
return angular.extend(lookup[str],obj);
317+
if (lookup[str]) {
318+
obj = angular.extend(lookup[str], obj);
320319
}
321320
}
322321

322+
// Special case: checkbox
323+
// Since have to ternary state we need a default
324+
if (obj.type === 'checkbox' && angular.isUndefined(obj.schema['default'])) {
325+
obj.schema['default'] = false;
326+
}
327+
323328
return obj;
324329
}));
325330
};

0 commit comments

Comments
 (0)