Skip to content

Commit 70d55b6

Browse files
committed
Release 0.8.13
Maintenance release 0.8.13 Bugfix copy the initial form default on form redraw @stanimoto Bugfix for revalidating the model after custom validation event is broadcast @cepauskas New event value. The form name is now passed in validate and error events @tomsowerby & @LeonardoGentile
1 parent f73411c commit 70d55b6

File tree

6 files changed

+143
-122
lines changed

6 files changed

+143
-122
lines changed

CHANGELOG

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v0.8.13
2+
-------
3+
* Bugfix copy the initial form default on form redraw @stanimoto
4+
* Bugfix for revalidating the model after custom validation event is broadcast @cepauskas
5+
* New event value. The form name is now passed in validate and error events @tomsowerby & @LeonardoGentile
6+
17
v0.8.12
28
-------
39
* Bugfix for `condition` builder. It had a typo that broke it.
@@ -118,14 +124,14 @@ v0.7.11
118124

119125
v0.7.10
120126
------
121-
* Accessability additions, thanks @stramel
122-
* Updates to the gulp tasks, thanks @stramel
123-
* Updated to bower, thanks @Dervisevic
124-
* Updates to documentation & README & Contributing.md, thanks @davidlgj @Dervisevic
125-
* Speed optimization, thanks @stramel
126-
* Call ngModel.$setDirty() when deleting from array, thanks @qstrahl
127-
* Don't override readonly if specified on items individually, thanks @qstrahl
128-
* Update to the examples, thanks @mike-marcacci
127+
* Accessability additions, thanks @stramel
128+
* Updates to the gulp tasks, thanks @stramel
129+
* Updated to bower, thanks @Dervisevic
130+
* Updates to documentation & README & Contributing.md, thanks @davidlgj @Dervisevic
131+
* Speed optimization, thanks @stramel
132+
* Call ngModel.$setDirty() when deleting from array, thanks @qstrahl
133+
* Don't override readonly if specified on items individually, thanks @qstrahl
134+
* Update to the examples, thanks @mike-marcacci
129135

130136
v0.7.9
131137
------
@@ -264,7 +270,7 @@ We're celebrating actual useful functionality by bumping minor version, yay!
264270

265271
v0.0.4
266272
------
267-
* Fieldsets now properly merge schema defaults.
268-
* Directives for "manual" decorator usage.
269-
* Basic support for buttons.
270-
* Basic support for custom validation error messages.
273+
* Fieldsets now properly merge schema defaults.
274+
* Directives for "manual" decorator usage.
275+
* Basic support for buttons.
276+
* Basic support for custom validation error messages.

dist/schema-form.js

+92-78
Original file line numberDiff line numberDiff line change
@@ -65,81 +65,6 @@ angular.module('schemaForm').provider('sfPath',
6565
};
6666
}]);
6767

68-
/**
69-
* @ngdoc service
70-
* @name sfSelect
71-
* @kind function
72-
*
73-
*/
74-
angular.module('schemaForm').factory('sfSelect', ['sfPath', function(sfPath) {
75-
var numRe = /^\d+$/;
76-
77-
/**
78-
* @description
79-
* Utility method to access deep properties without
80-
* throwing errors when things are not defined.
81-
* Can also set a value in a deep structure, creating objects when missing
82-
* ex.
83-
* var foo = Select('address.contact.name',obj)
84-
* Select('address.contact.name',obj,'Leeroy')
85-
*
86-
* @param {string} projection A dot path to the property you want to get/set
87-
* @param {object} obj (optional) The object to project on, defaults to 'this'
88-
* @param {Any} valueToSet (opional) The value to set, if parts of the path of
89-
* the projection is missing empty objects will be created.
90-
* @returns {Any|undefined} returns the value at the end of the projection path
91-
* or undefined if there is none.
92-
*/
93-
return function(projection, obj, valueToSet) {
94-
if (!obj) {
95-
obj = this;
96-
}
97-
//Support [] array syntax
98-
var parts = typeof projection === 'string' ? sfPath.parse(projection) : projection;
99-
100-
if (typeof valueToSet !== 'undefined' && parts.length === 1) {
101-
//special case, just setting one variable
102-
obj[parts[0]] = valueToSet;
103-
return obj;
104-
}
105-
106-
if (typeof valueToSet !== 'undefined' &&
107-
typeof obj[parts[0]] === 'undefined') {
108-
// We need to look ahead to check if array is appropriate
109-
obj[parts[0]] = parts.length > 2 && numRe.test(parts[1]) ? [] : {};
110-
}
111-
112-
var value = obj[parts[0]];
113-
for (var i = 1; i < parts.length; i++) {
114-
// Special case: We allow JSON Form syntax for arrays using empty brackets
115-
// These will of course not work here so we exit if they are found.
116-
if (parts[i] === '') {
117-
return undefined;
118-
}
119-
if (typeof valueToSet !== 'undefined') {
120-
if (i === parts.length - 1) {
121-
//last step. Let's set the value
122-
value[parts[i]] = valueToSet;
123-
return valueToSet;
124-
} else {
125-
// Make sure to create new objects on the way if they are not there.
126-
// We need to look ahead to check if array is appropriate
127-
var tmp = value[parts[i]];
128-
if (typeof tmp === 'undefined' || tmp === null) {
129-
tmp = numRe.test(parts[i + 1]) ? [] : {};
130-
value[parts[i]] = tmp;
131-
}
132-
value = tmp;
133-
}
134-
} else if (value) {
135-
//Just get nex value.
136-
value = value[parts[i]];
137-
}
138-
}
139-
return value;
140-
};
141-
}]);
142-
14368

14469
// FIXME: type template (using custom builder)
14570
angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(sfPathProvider) {
@@ -682,6 +607,9 @@ angular.module('schemaForm').provider('schemaFormDecorators',
682607
scope.ngModel.$setValidity(error, validity === true);
683608

684609
if (validity === true) {
610+
// Re-trigger model validator, that model itself would be re-validated
611+
scope.ngModel.$validate();
612+
685613
// Setting or removing a validity can change the field to believe its valid
686614
// but its not. So lets trigger its validation as well.
687615
scope.$broadcast('schemaFormValidate');
@@ -1553,6 +1481,81 @@ angular.module('schemaForm').provider('schemaForm',
15531481

15541482
}]);
15551483

1484+
/**
1485+
* @ngdoc service
1486+
* @name sfSelect
1487+
* @kind function
1488+
*
1489+
*/
1490+
angular.module('schemaForm').factory('sfSelect', ['sfPath', function(sfPath) {
1491+
var numRe = /^\d+$/;
1492+
1493+
/**
1494+
* @description
1495+
* Utility method to access deep properties without
1496+
* throwing errors when things are not defined.
1497+
* Can also set a value in a deep structure, creating objects when missing
1498+
* ex.
1499+
* var foo = Select('address.contact.name',obj)
1500+
* Select('address.contact.name',obj,'Leeroy')
1501+
*
1502+
* @param {string} projection A dot path to the property you want to get/set
1503+
* @param {object} obj (optional) The object to project on, defaults to 'this'
1504+
* @param {Any} valueToSet (opional) The value to set, if parts of the path of
1505+
* the projection is missing empty objects will be created.
1506+
* @returns {Any|undefined} returns the value at the end of the projection path
1507+
* or undefined if there is none.
1508+
*/
1509+
return function(projection, obj, valueToSet) {
1510+
if (!obj) {
1511+
obj = this;
1512+
}
1513+
//Support [] array syntax
1514+
var parts = typeof projection === 'string' ? sfPath.parse(projection) : projection;
1515+
1516+
if (typeof valueToSet !== 'undefined' && parts.length === 1) {
1517+
//special case, just setting one variable
1518+
obj[parts[0]] = valueToSet;
1519+
return obj;
1520+
}
1521+
1522+
if (typeof valueToSet !== 'undefined' &&
1523+
typeof obj[parts[0]] === 'undefined') {
1524+
// We need to look ahead to check if array is appropriate
1525+
obj[parts[0]] = parts.length > 2 && numRe.test(parts[1]) ? [] : {};
1526+
}
1527+
1528+
var value = obj[parts[0]];
1529+
for (var i = 1; i < parts.length; i++) {
1530+
// Special case: We allow JSON Form syntax for arrays using empty brackets
1531+
// These will of course not work here so we exit if they are found.
1532+
if (parts[i] === '') {
1533+
return undefined;
1534+
}
1535+
if (typeof valueToSet !== 'undefined') {
1536+
if (i === parts.length - 1) {
1537+
//last step. Let's set the value
1538+
value[parts[i]] = valueToSet;
1539+
return valueToSet;
1540+
} else {
1541+
// Make sure to create new objects on the way if they are not there.
1542+
// We need to look ahead to check if array is appropriate
1543+
var tmp = value[parts[i]];
1544+
if (typeof tmp === 'undefined' || tmp === null) {
1545+
tmp = numRe.test(parts[i + 1]) ? [] : {};
1546+
value[parts[i]] = tmp;
1547+
}
1548+
value = tmp;
1549+
}
1550+
} else if (value) {
1551+
//Just get nex value.
1552+
value = value[parts[i]];
1553+
}
1554+
}
1555+
return value;
1556+
};
1557+
}]);
1558+
15561559
/* Common code for validating a value against its form and schema definition */
15571560
/* global tv4 */
15581561
angular.module('schemaForm').factory('sfValidator', [function() {
@@ -2109,6 +2112,9 @@ angular.module('schemaForm').directive('sfField',
21092112
scope.ngModel.$setValidity(error, validity === true);
21102113

21112114
if (validity === true) {
2115+
// Re-trigger model validator, that model itself would be re-validated
2116+
scope.ngModel.$validate();
2117+
21122118
// Setting or removing a validity can change the field to believe its valid
21132119
// but its not. So lets trigger its validation as well.
21142120
scope.$broadcast('schemaFormValidate');
@@ -2677,7 +2683,7 @@ angular.module('schemaForm')
26772683
// part of the form or schema is chnaged without it being a new instance.
26782684
scope.$on('schemaFormRedraw', function() {
26792685
var schema = scope.schema;
2680-
var form = scope.initialForm || ['*'];
2686+
var form = scope.initialForm ? angular.copy(scope.initialForm) : ['*'];
26812687
if (schema) {
26822688
render(schema, form);
26832689
}
@@ -2817,7 +2823,13 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
28172823
var schema = form.schema;
28182824

28192825
// A bit ugly but useful.
2820-
scope.validateField = function() {
2826+
scope.validateField = function(formName) {
2827+
2828+
// If we have specified a form name, and this model is not within
2829+
// that form, then leave things be.
2830+
if(formName != undefined && ngModel.$$parentForm.$name !== formName) {
2831+
return;
2832+
}
28212833

28222834
// Special case: arrays
28232835
// TODO: Can this be generalized in a way that works consistently?
@@ -2864,7 +2876,9 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
28642876
});
28652877

28662878
// Listen to an event so we can validate the input on request
2867-
scope.$on('schemaFormValidate', scope.validateField);
2879+
scope.$on('schemaFormValidate', function(event, formName) {
2880+
scope.validateField(formName);
2881+
});
28682882

28692883
scope.schemaError = function() {
28702884
return error;

dist/schema-form.min.js

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

gulp/tasks/jscs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var gulp = require('gulp'),
2-
jscs = require('gulp-jscs');
1+
var gulp = require('gulp');
2+
var jscs = require('gulp-jscs');
33

44
gulp.task('jscs', function() {
55
gulp.src('./src/**/*.js')

gulp/tasks/minify.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
var gulp = require('gulp'),
2-
concat = require('gulp-concat'),
3-
rename = require('gulp-rename'),
4-
umd = require('gulp-umd'),
5-
uglify = require('gulp-uglify');
1+
var gulp = require('gulp');
2+
var concat = require('gulp-concat');
3+
var rename = require('gulp-rename');
4+
var umd = require('gulp-umd');
5+
var uglify = require('gulp-uglify');
66

77
gulp.task('minify', function() {
88
gulp.src([
9-
'./src/module.js',
10-
'./src/sfPath.js',
11-
'./src/services/*.js',
12-
'./src/directives/*.js'
9+
'./src/module.js',
10+
'./src/sfPath.js',
11+
'./src/services/*.js',
12+
'./src/directives/*.js'
1313
])
14-
.pipe(concat('schema-form.js'))
15-
.pipe(umd({
16-
dependencies: function() {
17-
return [
18-
{name: 'angular'},
19-
{name: 'objectpath'},
20-
{name: 'tv4'},
21-
];
22-
},
23-
exports: function() {return 'schemaForm';},
24-
namespace: function() {return 'schemaForm';}
14+
.pipe(concat('schema-form.js'))
15+
.pipe(umd({
16+
dependencies: function() {
17+
return [
18+
{name: 'angular'},
19+
{name: 'objectpath'},
20+
{name: 'tv4'},
21+
];
22+
},
23+
exports: function() {return 'schemaForm';},
24+
namespace: function() {return 'schemaForm';}
2525
}))
26-
.pipe(gulp.dest('./dist/'))
27-
.pipe(uglify())
28-
.pipe(rename('schema-form.min.js'))
29-
.pipe(gulp.dest('./dist/'));
26+
.pipe(gulp.dest('./dist/'))
27+
.pipe(uglify())
28+
.pipe(rename('schema-form.min.js'))
29+
.pipe(gulp.dest('./dist/'));
3030
});

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-schema-form",
3-
"version": "0.8.12",
3+
"version": "0.8.13",
44
"description": "Create complex forms from a JSON schema with angular.",
55
"repository": "Textalk/angular-schema-form",
66
"main": "dist/schema-form.min.js",
@@ -14,7 +14,8 @@
1414
"David Jensen <[email protected]> (https://github.com/davidlgj)",
1515
"Denis Dervisevic <[email protected]> (https://github.com/Dervisevic)",
1616
"Cameron Edwards (https://github.com/cameronprattedwards)",
17-
"Mike Marcacci (https://github.com/mike-marcacci)"
17+
"Mike Marcacci (https://github.com/mike-marcacci)",
18+
"Marcel Bennett (https://github.com/Anthropic)"
1819
],
1920
"license": "MIT",
2021
"dependencies": {
@@ -29,6 +30,8 @@
2930
"form",
3031
"json",
3132
"json-schema",
33+
"json-schema-form",
34+
"ui-schema",
3235
"schema"
3336
],
3437
"devDependencies": {
@@ -68,9 +71,7 @@
6871
"basePath": "/dist/",
6972
"files": [
7073
"schema-form.min.js",
71-
"schema-form.js",
72-
"bootstrap-decorator.min.js",
73-
"bootstrap-decorator.js"
74+
"schema-form.js"
7475
]
7576
}
7677
}

0 commit comments

Comments
 (0)