Skip to content

Commit e72b977

Browse files
committed
Merge branch 'release/0.7.7'
2 parents ac29fb9 + b01b6d6 commit e72b977

14 files changed

+401
-90
lines changed

Diff for: CHANGELOG

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
v0.7.7
2+
------
3+
* Array ref changes in model updates form, thanks @Sandreu
4+
* Tabarray & array fixes, thanks @Sandreu, @davidlgj
5+
* Use objectpath more generically to fix requirejs issues, thanks @mike-marcacci
6+
* README and documentation updates, thanks @davidlgj, @engelfrost, @Dervisevic, @stramel, @Sandreu
7+
* Expanded documentation on custom validation messages, thanks @Dervisevic
8+
* Deep structure tests, thanks @Sandreu
9+
* SF-insert-field documentation, thanks @davidlgj
10+
* Array model watch & array defaults, thanks @Sandreu
11+
112
v0.7.6
213
------
314
* Fixed broken bower specification.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ apart from JSON Form?
3636

3737
Documentation
3838
-------------
39-
Documentation covering defaults and form types [can be found here](docs/index.md). And you can find the documentation for how you extend angular schema form with your own types [here](https://github.com/Textalk/angular-schema-form/blob/master/docs/extending.md).
39+
There is one section of documentation covering [defaults and form types](docs/index.md). There is another section for how you [extend angular schema form with your own types](https://github.com/Textalk/angular-schema-form/blob/master/docs/extending.md).
4040

4141
Basic Usage
4242
-----------

Diff for: bower.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dist/schema-form.min.js",
55
"dist/bootstrap-decorator.min.js"
66
],
7-
"version": "0.7.6",
7+
"version": "0.7.7",
88
"authors": [
99
"Textalk",
1010
"David Jensen <[email protected]>"
@@ -32,7 +32,7 @@
3232
"angular": ">= 1.2",
3333
"tv4": "~1.0.15",
3434
"angular-sanitize": ">= 1.2",
35-
"objectpath": "~1.0.4"
35+
"objectpath": "~1.1.0"
3636
},
3737
"devDependencies": {
3838
"angular-ui-ace": "bower",

Diff for: dist/bootstrap-decorator.min.js

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

Diff for: dist/schema-form.js

+66-32
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Deps is sort of a problem for us, maybe in the future we will ask the user to depend
22
// on modules for add-ons
33

4-
var deps = ['ObjectPath'];
4+
var deps = [];
55
try {
66
//This throws an expection if module does not exist.
77
angular.module('ngSanitize');
@@ -23,29 +23,31 @@ try {
2323
angular.module('schemaForm', deps);
2424

2525
angular.module('schemaForm').provider('sfPath',
26-
['ObjectPathProvider', function(ObjectPathProvider) {
27-
var ObjectPath = {parse: ObjectPathProvider.parse};
26+
[function() {
27+
var sfPath = {parse: ObjectPath.parse};
2828

2929
// if we're on Angular 1.2.x, we need to continue using dot notation
3030
if (angular.version.major === 1 && angular.version.minor < 3) {
31-
ObjectPath.stringify = function(arr) {
31+
sfPath.stringify = function(arr) {
3232
return Array.isArray(arr) ? arr.join('.') : arr.toString();
3333
};
3434
} else {
35-
ObjectPath.stringify = ObjectPathProvider.stringify;
35+
sfPath.stringify = ObjectPath.stringify;
3636
}
3737

3838
// We want this to use whichever stringify method is defined above,
3939
// so we have to copy the code here.
40-
ObjectPath.normalize = function(data, quote) {
41-
return ObjectPath.stringify(Array.isArray(data) ? data : ObjectPath.parse(data), quote);
40+
sfPath.normalize = function(data, quote) {
41+
return sfPath.stringify(Array.isArray(data) ? data : sfPath.parse(data), quote);
4242
};
4343

44-
this.parse = ObjectPath.parse;
45-
this.stringify = ObjectPath.stringify;
46-
this.normalize = ObjectPath.normalize;
44+
// expose the methods in sfPathProvider
45+
this.parse = sfPath.parse;
46+
this.stringify = sfPath.stringify;
47+
this.normalize = sfPath.normalize;
48+
4749
this.$get = function() {
48-
return ObjectPath;
50+
return sfPath;
4951
};
5052
}]);
5153

@@ -949,8 +951,8 @@ angular.module('schemaForm').factory('sfValidator', [function() {
949951
/**
950952
* Directive that handles the model arrays
951953
*/
952-
angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sfValidator',
953-
function(sfSelect, schemaForm, sfValidator) {
954+
angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sfValidator', 'sfPath',
955+
function(sfSelect, schemaForm, sfValidator, sfPath) {
954956

955957
var setIndex = function(index) {
956958
return function(form) {
@@ -977,6 +979,14 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
977979
// other hand it enables two way binding.
978980
var list = sfSelect(form.key, scope.model);
979981

982+
// We only modify the same array instance but someone might change the array from
983+
// the outside so let's watch for that. We use an ordinary watch since the only case
984+
// we're really interested in is if its a new instance.
985+
scope.$watch('model' + sfPath.normalize(form.key), function() {
986+
list = sfSelect(form.key, scope.model);
987+
scope.modelArray = list;
988+
});
989+
980990
// Since ng-model happily creates objects in a deep path when setting a
981991
// a value but not arrays we need to create the array.
982992
if (angular.isUndefined(list)) {
@@ -996,7 +1006,7 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
9961006
if (form.items.length > 1) {
9971007
subForm = {
9981008
type: 'section',
999-
items: form.items.map(function(item){
1009+
items: form.items.map(function(item) {
10001010
item.ngModelOptions = form.ngModelOptions;
10011011
item.readonly = form.readonly;
10021012
return item;
@@ -1024,8 +1034,20 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
10241034
var len = list.length;
10251035
var copy = scope.copyWithIndex(len);
10261036
schemaForm.traverseForm(copy, function(part) {
1027-
if (part.key && angular.isDefined(part['default'])) {
1028-
sfSelect(part.key, scope.model, part['default']);
1037+
1038+
if (part.key) {
1039+
var def;
1040+
if (angular.isDefined(part['default'])) {
1041+
def = part['default'];
1042+
}
1043+
if (angular.isDefined(part.schema) &&
1044+
angular.isDefined(part.schema['default'])) {
1045+
def = part.schema['default'];
1046+
}
1047+
1048+
if (angular.isDefined(def)) {
1049+
sfSelect(part.key, scope.model, def);
1050+
}
10291051
}
10301052
});
10311053

@@ -1201,8 +1223,8 @@ FIXME: real documentation
12011223

12021224
angular.module('schemaForm')
12031225
.directive('sfSchema',
1204-
['$compile', 'schemaForm', 'schemaFormDecorators', 'sfSelect',
1205-
function($compile, schemaForm, schemaFormDecorators, sfSelect) {
1226+
['$compile', 'schemaForm', 'schemaFormDecorators', 'sfSelect', 'sfPath',
1227+
function($compile, schemaForm, schemaFormDecorators, sfSelect, sfPath) {
12061228

12071229
var SNAKE_CASE_REGEXP = /[A-Z]/g;
12081230
var snakeCase = function(name, separator) {
@@ -1279,23 +1301,35 @@ angular.module('schemaForm')
12791301
//clean all but pre existing html.
12801302
element.children(':not(.schema-form-ignore)').remove();
12811303

1304+
// Find all slots.
1305+
var slots = {};
1306+
var slotsFound = element[0].querySelectorAll('*[sf-insert-field]');
1307+
1308+
for (var i = 0; i < slotsFound.length; i++) {
1309+
slots[slotsFound[i].getAttribute('sf-insert-field')] = slotsFound[i];
1310+
}
1311+
12821312
//Create directives from the form definition
1283-
angular.forEach(merged,function(obj,i){
1284-
var n = document.createElement(attrs.sfDecorator || snakeCase(schemaFormDecorators.defaultDecorator,'-'));
1313+
angular.forEach(merged, function(obj, i) {
1314+
var n = document.createElement(attrs.sfDecorator ||
1315+
snakeCase(schemaFormDecorators.defaultDecorator, '-'));
12851316
n.setAttribute('form','schemaForm.form['+i+']');
1286-
var slot;
1287-
try {
1288-
slot = element[0].querySelector('*[sf-insert-field="' + obj.key + '"]');
1289-
} catch(err) {
1290-
// field insertion not supported for complex keys
1291-
slot = null;
1292-
}
1293-
if(slot) {
1294-
slot.innerHTML = "";
1295-
slot.appendChild(n);
1296-
} else {
1297-
frag.appendChild(n);
1317+
1318+
// Check if there is a slot to put this in...
1319+
if (obj.key) {
1320+
var slot = slots[sfPath.stringify(obj.key)];
1321+
if (slot) {
1322+
while (slot.firstChild) {
1323+
slot.removeChild(slot.firstChild);
1324+
}
1325+
slot.appendChild(n);
1326+
return;
1327+
}
12981328
}
1329+
1330+
// ...otherwise add it to the frag
1331+
frag.appendChild(n);
1332+
12991333
});
13001334

13011335
element[0].appendChild(frag);

0 commit comments

Comments
 (0)