Skip to content

Commit a5d422c

Browse files
committed
All working except fieldset
1 parent edec694 commit a5d422c

File tree

11 files changed

+1390
-27
lines changed

11 files changed

+1390
-27
lines changed

dist/bootstrap-datepicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/schema-form.min.js

Lines changed: 1189 additions & 1 deletion
Large diffs are not rendered by default.

examples/bootstrap-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h3>Schema</h3>
6161
<script type="text/javascript" src="http://cdn.jsdelivr.net/g/[email protected]"></script>
6262
<script type="text/javascript" src="../bower_components/tv4/tv4.js"></script>
6363
<script type="text/javascript" src="../bower_components/ace-builds/src-min-noconflict/ace.js"></script>
64-
<script type="text/javascript" src="../bower_components/angular/angular.min.js"></script>
64+
<script type="text/javascript" src="../bower_components/angular/angular.js"></script>
6565
<script type="text/javascript" src="../bower_components/angular-sanitize/angular-sanitize.min.js"></script>
6666
<script type="text/javascript" src="../bower_components/angular-ui-sortable/sortable.js"></script>
6767
<script type="text/javascript" src="../bower_components/angular-ui-ace/ui-ace.js"></script>
@@ -78,6 +78,7 @@ <h3>Schema</h3>
7878
function TestCtrl($scope,$http){
7979

8080
$scope.tests = [
81+
{ name: "Complex Key Support", data: 'data/keys.json' },
8182
{ name: "Simple", data: 'data/simple.json' },
8283
{ name: "Array", data: 'data/array.json' },
8384
{ name: "Tab Array", data: 'data/tabarray.json' },

examples/data/keys.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"schema": {
3+
"type": "object",
4+
"title": "Complex Key Support",
5+
"properties": {
6+
"a[\"b\"].c": {
7+
"type": "text",
8+
"title": "Paths do not overflow their keys."
9+
},
10+
"simple": {
11+
"type": "object",
12+
"properties": {
13+
"prøp": {
14+
"title": "Property",
15+
"type": "string"
16+
}
17+
}
18+
},
19+
"array-key": {
20+
"type": "array",
21+
"items": {
22+
"type": "object",
23+
"properties": {
24+
"a'rr[\"l": {
25+
"title": "Control Characters",
26+
"type": "string"
27+
},
28+
"˙∆∂∞˚¬": {
29+
"type": "string"
30+
}
31+
},
32+
"required": [
33+
"a'rr[\"l",
34+
"˙∆∂∞˚¬"
35+
]
36+
}
37+
}
38+
}
39+
},
40+
"form": ["*"],
41+
"form1": [
42+
"['a[\"b\"].c']",
43+
{
44+
"key": "array-key",
45+
"items": [
46+
"[array-key][]['a'rr[\"l']",
47+
{
48+
"key": "[array-key][][˙∆∂∞˚¬]",
49+
"title": "Unicode Characters"
50+
}
51+
]
52+
},
53+
{
54+
"key": "simple",
55+
"items": [
56+
"simple.prøp"
57+
]
58+
}
59+
]
60+
}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ gulp.task('minify',function(){
6464
'./src/directives/*.js'
6565
])
6666
.pipe(concat('schema-form.min.js'))
67-
.pipe(uglify())
67+
// .pipe(uglify())
6868
.pipe(gulp.dest('./dist/'));
6969
});
7070

src/directives/array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function(sfSelect, schemaForm) {
77
var setIndex = function(index) {
88
return function(form) {
99
if (form.key) {
10-
form.key = form.key.replace('[]','['+index+']');
10+
form.key[form.key.indexOf('')] = index;
1111
}
1212
};
1313
};

src/directives/decorators/bootstrap/datepicker/bootstrap-datepicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function(schemaFormProvider, schemaFormDecoratorsProvider){
77
var f = schemaFormProvider.stdFormObj(schema,options);
88
f.key = options.path;
99
f.type = 'datepicker';
10-
options.lookup[options.path] = f;
10+
options.lookup[ObjectPath.stringify(options.path)] = f;
1111
return f;
1212
}
1313
};

src/module.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,96 @@ try {
1212
} catch (e) {}
1313

1414
angular.module('schemaForm',deps);
15+
16+
17+
'use strict';
18+
19+
;!function(undefined) {
20+
21+
var ObjectPath = {
22+
parse: function(str){
23+
if(typeof str !== 'string'){
24+
console.log(str)
25+
throw new TypeError('ObjectPath.parse must be passed a string');
26+
}
27+
28+
var i = 0;
29+
var parts = [];
30+
var d, b, q, c;
31+
while (i < str.length){
32+
d = str.indexOf('.', i);
33+
b = str.indexOf('[', i);
34+
35+
// we've reached the end
36+
if (d === -1 && b === -1){
37+
parts.push(str.slice(i, str.length));
38+
i = str.length;
39+
}
40+
41+
// dots
42+
else if (b === -1 || (d !== -1 && d < b)) {
43+
parts.push(str.slice(i, d));
44+
i = d + 1;
45+
}
46+
47+
// brackets
48+
else {
49+
if (b > i){
50+
parts.push(str.slice(i, b));
51+
i = b;
52+
}
53+
q = str.slice(b+1, b+2);
54+
if (q !== '"' && q !=='\'') {
55+
c = str.indexOf(']', b);
56+
if (c === -1) c = str.length;
57+
parts.push(str.slice(i + 1, c));
58+
i = (str.slice(c + 1, c + 2) === '.') ? c + 2 : c + 1;
59+
} else {
60+
c = str.indexOf(q+']', b);
61+
if (c === -1) c = str.length;
62+
while (str.slice(c - 1, c) === '\\' && b < str.length){
63+
b++;
64+
c = str.indexOf(q+']', b);
65+
}
66+
parts.push(str.slice(i + 2, c).replace(new RegExp('\\'+q,'g'), q));
67+
i = (str.slice(c + 2, c + 3) === '.') ? c + 3 : c + 2;
68+
}
69+
}
70+
}
71+
return parts;
72+
},
73+
74+
// root === true : auto calculate root; must be dot-notation friendly
75+
// root String : the string to use as root
76+
stringify: function(arr, quote){
77+
78+
if(Array.isArray(arr) !== true)
79+
arr = [arr.toString()];
80+
81+
quote = quote === '"' ? '"' : '\'';
82+
83+
return arr.slice().map(function(n){ return '[' + quote + (n.toString()).replace(new RegExp(quote, 'g'), '\\' + quote) + quote + ']'; }).join('');
84+
},
85+
86+
normalize: function(str){
87+
return this.stringify(this.parse(str));
88+
}
89+
};
90+
91+
// AMD
92+
if (typeof define === 'function' && define.amd) {
93+
define(function() {
94+
return ObjectPath;
95+
});
96+
}
97+
98+
// CommonJS
99+
else if (typeof exports === 'object') {
100+
exports.ObjectPath = ObjectPath;
101+
}
102+
103+
// Browser global.
104+
else {
105+
window.ObjectPath = ObjectPath;
106+
}
107+
}();

src/services/Select.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
* or undefined if there is none.
2020
*/
2121
angular.module('schemaForm').factory('sfSelect', [function () {
22-
var re = /\[(\d+)\]/g;
2322
var numRe = /^\d+$/;
2423

2524
return function(projection, obj, valueToSet) {
2625
if (!obj) {
2726
obj = this;
2827
}
2928
//Support [] array syntax
30-
var parts = projection.replace(re, '.$1').split('.');
29+
var parts = typeof projection === 'string' ? ObjectPath.parse(projection) : projection;
3130

3231
if (typeof valueToSet !== 'undefined' && parts.length === 1) {
3332
//special case, just setting one variable
@@ -45,7 +44,7 @@ angular.module('schemaForm').factory('sfSelect', [function () {
4544
for (var i = 1; i < parts.length; i++) {
4645
// Special case: We allow JSON Form syntax for arrays using empty brackets
4746
// These will of course not work here so we exit if they are found.
48-
if (parts[i] === '[]') {
47+
if (parts[i] === '') {
4948
return undefined;
5049
}
5150
if (typeof valueToSet !== 'undefined') {

src/services/decorators.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ angular.module('schemaForm').provider('schemaFormDecorators',['$compileProvider'
5151
//for fieldsets to recurse properly.
5252
var url = templateUrl(name,form);
5353
$http.get(url,{ cache: $templateCache }).then(function(res){
54-
var template = res.data.replace(/\$\$value\$\$/g,'model.'+(form.key || ""));
54+
var key = form.key ? ObjectPath.stringify(form.key).replace(/"/g, '&quot;') : '';
55+
var template = res.data.replace(/\$\$value\$\$/g,'model'+key);
5556
$compile(template)(scope,function(clone){
5657
element.replaceWith(clone);
5758
});

0 commit comments

Comments
 (0)