Skip to content

Commit a17c80a

Browse files
committed
Fixed array not defaulting
1 parent 395aebc commit a17c80a

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

bundle.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ return /******/ (function(modules) { // webpackBootstrap
214214
// Since have to ternary state we need a default
215215
if (obj.type === 'checkbox' && obj.schema['default'] === undefined) {
216216
obj.schema['default'] = false;
217-
}
217+
};
218218

219219
// Special case: template type with tempplateUrl that's needs to be loaded before rendering
220220
// TODO: this is not a clean solution. Maybe something cleaner can be made when $ref support
@@ -591,9 +591,13 @@ return /******/ (function(modules) { // webpackBootstrap
591591
/* Utils */
592592
var stripNullType = function stripNullType(type) {
593593
if (Array.isArray(type) && type.length == 2) {
594-
if (type[0] === 'null') return type[1];
595-
if (type[1] === 'null') return type[0];
596-
}
594+
if (type[0] === 'null') {
595+
return type[1];
596+
};
597+
if (type[1] === 'null') {
598+
return type[0];
599+
};
600+
};
597601
return type;
598602
};
599603

@@ -685,7 +689,7 @@ return /******/ (function(modules) { // webpackBootstrap
685689
f.ngModelOptions = f.ngModelOptions || {};
686690

687691
return f;
688-
}
692+
};
689693

690694
/*** Schema types to form type mappings, with defaults ***/
691695
function text(name, schema, options) {
@@ -833,9 +837,11 @@ return /******/ (function(modules) { // webpackBootstrap
833837
object: [fieldset],
834838
number: [number],
835839
integer: [integer],
836-
boolean: [checkbox], defaultForm: defaultForm
840+
boolean: [checkbox],
841+
array: [array],
842+
defaultForm: defaultForm
837843
};
838-
}
844+
};
839845

840846
/**
841847
* Create form defaults from schema

lib/merge.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {stringify, parse} from './sfPath';
22
import canonicalTitleMap from './canonicalTitleMap';
33

4-
54
//export function merge(schema, form, schemaDefaultTypes, ignore, options, readonly, asyncTemplates) {
65
export function merge(lookup, form, options, readonly, asyncTemplates) {
76
form = form || [];
@@ -13,7 +12,7 @@ export function merge(lookup, form, options, readonly, asyncTemplates) {
1312

1413
//handle the shortcut with just a name
1514
if (typeof obj === 'string') {
16-
obj = {key: obj};
15+
obj = { key: obj };
1716
}
1817

1918
if (obj.key) {
@@ -65,7 +64,7 @@ export function merge(lookup, form, options, readonly, asyncTemplates) {
6564
// Since have to ternary state we need a default
6665
if (obj.type === 'checkbox' && obj.schema['default'] === undefined) {
6766
obj.schema['default'] = false;
68-
}
67+
};
6968

7069
// Special case: template type with tempplateUrl that's needs to be loaded before rendering
7170
// TODO: this is not a clean solution. Maybe something cleaner can be made when $ref support

lib/schemaDefaults.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@ import canonicalTitleMap from './canonicalTitleMap';
44
/* Utils */
55
const stripNullType = (type) => {
66
if (Array.isArray(type) && type.length == 2) {
7-
if (type[0] === 'null')
7+
if (type[0] === 'null') {
88
return type[1];
9-
if (type[1] === 'null')
9+
};
10+
if (type[1] === 'null') {
1011
return type[0];
11-
}
12+
};
13+
};
1214
return type;
1315
};
1416

1517
//Creates an default titleMap list from an enum, i.e. a list of strings.
1618
const enumToTitleMap = (enm) => {
1719
const titleMap = []; //canonical titleMap format is a list.
1820
enm.forEach((name) => {
19-
titleMap.push({name, value: name});
21+
titleMap.push({ name, value: name });
2022
});
2123
return titleMap;
2224
};
2325

24-
2526
/**
2627
* Creates a default form definition from a schema.
2728
*/
@@ -83,8 +84,7 @@ export function stdFormObj(name, schema, options) {
8384
f.ngModelOptions = f.ngModelOptions || {};
8485

8586
return f;
86-
}
87-
87+
};
8888

8989
/*** Schema types to form type mappings, with defaults ***/
9090
export function text(name, schema, options) {
@@ -162,7 +162,7 @@ export function fieldset(name, schema, options, defaultFormDef) {
162162
f.items = [];
163163
options.lookup[stringify(options.path)] = f;
164164

165-
console.log('fieldset', f, schema)
165+
console.log('fieldset', f, schema);
166166
//recurse down into properties
167167
if (schema.properties) {
168168
Object.keys(schema.properties).forEach((key) => {
@@ -207,13 +207,15 @@ export function array(name, schema, options, defaultFormDef) {
207207
const arrPath = options.path.slice();
208208
arrPath.push('');
209209

210-
f.items = [defaultFormDef(name, schema.items, {
211-
path: arrPath,
212-
required: required || false,
213-
lookup: options.lookup,
214-
ignore: options.ignore,
215-
global: options.global
216-
})];
210+
f.items = [
211+
defaultFormDef(name, schema.items, {
212+
path: arrPath,
213+
required: required || false,
214+
lookup: options.lookup,
215+
ignore: options.ignore,
216+
global: options.global
217+
})
218+
];
217219

218220
return f;
219221
}
@@ -223,14 +225,15 @@ export function createDefaults() {
223225
//First sorted by schema type then a list.
224226
//Order has importance. First handler returning an form snippet will be used.
225227
return {
226-
string: [select, text],
227-
object: [fieldset],
228-
number: [number],
229-
integer: [integer],
230-
boolean: [checkbox],defaultForm
228+
string: [ select, text ],
229+
object: [ fieldset ],
230+
number: [ number ],
231+
integer: [ integer ],
232+
boolean: [ checkbox ],
233+
array: [ array ],
234+
defaultForm: defaultForm
231235
};
232-
}
233-
236+
};
234237

235238
/**
236239
* Create form defaults from schema
@@ -246,7 +249,7 @@ export function defaultForm(schema, defaultSchemaTypes, ignore, globalOptions) {
246249
if (ignore[key] !== true) {
247250
const required = schema.required && schema.required.indexOf(key) !== -1;
248251
const def = defaultFormDefinition(defaultSchemaTypes, key, schema.properties[key], {
249-
path: [key], // Path to this property in bracket notation.
252+
path: [ key ], // Path to this property in bracket notation.
250253
lookup: lookup, // Extra map to register with. Optimization for merger.
251254
ignore: ignore, // The ignore list of paths (sans root level name)
252255
required: required, // Is it required? (v4 json schema style)
@@ -261,5 +264,5 @@ export function defaultForm(schema, defaultSchemaTypes, ignore, globalOptions) {
261264
} else {
262265
throw new Error('Not implemented. Only type "object" allowed at root level of schema.');
263266
}
264-
return {form: form, lookup: lookup};
267+
return { form: form, lookup: lookup };
265268
}

0 commit comments

Comments
 (0)