Skip to content

Commit d33a8e3

Browse files
committed
Fixes #563
1 parent 9e4a70c commit d33a8e3

7 files changed

+60
-36
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ This alpha fixes a bunch of array and destroyStrategy bugs.
1212

1313
### Added
1414
- #612 Added 'required' class to allow appending to or highlighting content when a field is required
15+
- Added test case for onChange support for array type
1516

1617
### Fixed
18+
- #563 copyValueTo doesn't work with arrays
1719

1820
v1.0.0-alpha.4
1921
--------------

dist/angular-schema-form-bootstrap.js

+12-12
Large diffs are not rendered by default.

dist/angular-schema-form-bootstrap.min.js

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

dist/angular-schema-form.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-schema-form
3-
* @version 1.0.0-alpha.4
4-
* @date Sat, 15 Apr 2017 08:27:27 GMT
3+
* @version 1.0.0-alpha.5
4+
* @date Wed, 26 Apr 2017 14:49:08 GMT
55
* @link https://github.com/json-schema-form/angular-schema-form
66
* @license MIT
77
* Copyright (c) 2014-2017 JSON Schema Form
@@ -2831,7 +2831,7 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
28312831
})
28322832

28332833
// Directives
2834-
.directive('sfChanged', __WEBPACK_IMPORTED_MODULE_7_sf_changed_directive__["a" /* default */]).directive('sfField', ['$parse', '$compile', '$http', '$templateCache', '$interpolate', '$q', 'sfErrorMessage', 'sfPath', 'sfSelect', __WEBPACK_IMPORTED_MODULE_8_sf_field_directive__["a" /* default */]]).directive('sfMessage', ['$injector', 'sfErrorMessage', __WEBPACK_IMPORTED_MODULE_9_sf_message_directive__["a" /* default */]]).directive('sfNewArray', ['sfSelect', 'sfPath', 'schemaForm', __WEBPACK_IMPORTED_MODULE_10_sf_array_directive__["a" /* default */]]).directive('sfSchema', ['$compile', '$http', '$templateCache', '$q', 'schemaForm', 'schemaFormDecorators', 'sfSelect', 'sfPath', 'sfBuilder', __WEBPACK_IMPORTED_MODULE_12_sf_schema_directive__["a" /* default */]]).directive('schemaValidate', ['sfValidator', '$parse', 'sfSelect', __WEBPACK_IMPORTED_MODULE_13_schema_validate_directive__["a" /* default */]]).directive('sfKeyController', ['schemaForm', 'sfPath', __WEBPACK_IMPORTED_MODULE_11_sf_key_directive__["a" /* default */]]);
2834+
.directive('sfChanged', __WEBPACK_IMPORTED_MODULE_7_sf_changed_directive__["a" /* default */]).directive('sfField', ['$parse', '$compile', '$http', '$templateCache', '$interpolate', '$q', 'sfErrorMessage', 'sfPath', 'sfSelect', __WEBPACK_IMPORTED_MODULE_8_sf_field_directive__["a" /* default */]]).directive('sfMessage', ['$injector', 'sfErrorMessage', __WEBPACK_IMPORTED_MODULE_9_sf_message_directive__["a" /* default */]]).directive('sfNewArray', ['sfSelect', 'sfPath', 'schemaForm', __WEBPACK_IMPORTED_MODULE_10_sf_array_directive__["a" /* default */]]).directive('sfSchema', ['$compile', '$http', '$templateCache', '$q', 'schemaForm', 'schemaFormDecorators', 'sfSelect', 'sfPath', 'sfBuilder', __WEBPACK_IMPORTED_MODULE_12_sf_schema_directive__["a" /* default */]]).directive('schemaValidate', ['sfValidator', '$parse', 'sfSelect', '$interpolate', __WEBPACK_IMPORTED_MODULE_13_schema_validate_directive__["a" /* default */]]).directive('sfKeyController', ['schemaForm', 'sfPath', __WEBPACK_IMPORTED_MODULE_11_sf_key_directive__["a" /* default */]]);
28352835

28362836
/***/ }),
28372837
/* 5 */
@@ -2842,7 +2842,7 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
28422842
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_angular___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_angular__);
28432843

28442844

2845-
/* harmony default export */ __webpack_exports__["a"] = function (sfValidator, $parse, sfSelect) {
2845+
/* harmony default export */ __webpack_exports__["a"] = function (sfValidator, $parse, sfSelect, $interpolate) {
28462846
return {
28472847
restrict: 'A',
28482848
scope: false,
@@ -2859,15 +2859,26 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
28592859
var error = null;
28602860
var form = scope.$eval(attrs.schemaValidate);
28612861

2862-
if (form.copyValueTo) {
2862+
//TODO move this out of validate
2863+
var copyTo = typeof form.copyValueTo === 'string' ? [form.copyValueTo] : form.copyValueTo;
2864+
if (copyTo && copyTo.length) {
28632865
ngModel.$viewChangeListeners.push(function () {
2864-
var paths = form.copyValueTo;
2865-
__WEBPACK_IMPORTED_MODULE_0_angular___default.a.forEach(paths, function (path) {
2866+
var context = {
2867+
"model": scope.model,
2868+
"form": form,
2869+
"arrayIndex": scope.$index,
2870+
"arrayIndices": scope.arrayIndices,
2871+
"path": scope.path,
2872+
"$i": scope.$i,
2873+
"$index": scope.$index
2874+
};
2875+
__WEBPACK_IMPORTED_MODULE_0_angular___default.a.forEach(copyTo, function (copyToPath) {
2876+
var path = copyToPath.replace(/\[/g, "[{{ ").replace(/\]/g, " }}]").replace(/^model\./, "");
2877+
path = $interpolate(path)(context);
28662878
sfSelect(path, scope.model, ngModel.$modelValue);
28672879
});
28682880
});
28692881
};
2870-
28712882
// Validate against the schema.
28722883

28732884
var validate = function validate(viewValue, triggered) {

dist/angular-schema-form.min.js

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

src/directives/schema-validate.directive.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import angular from 'angular';
22

3-
export default function(sfValidator, $parse, sfSelect) {
3+
export default function(sfValidator, $parse, sfSelect, $interpolate) {
44
return {
55
restrict: 'A',
66
scope: false,
@@ -17,15 +17,26 @@ export default function(sfValidator, $parse, sfSelect) {
1717
var error = null;
1818
var form = scope.$eval(attrs.schemaValidate);
1919

20-
if (form.copyValueTo) {
20+
//TODO move this out of validate
21+
var copyTo = (typeof form.copyValueTo === 'string')? [ form.copyValueTo ]: form.copyValueTo;
22+
if (copyTo && copyTo.length) {
2123
ngModel.$viewChangeListeners.push(function() {
22-
var paths = form.copyValueTo;
23-
angular.forEach(paths, function(path) {
24+
var context = {
25+
"model": scope.model,
26+
"form": form,
27+
"arrayIndex": scope.$index,
28+
"arrayIndices": scope.arrayIndices,
29+
"path": scope.path,
30+
"$i": scope.$i,
31+
"$index": scope.$index
32+
};
33+
angular.forEach(copyTo, function(copyToPath) {
34+
var path = copyToPath.replace(/\[/g,"[{{ ").replace(/\]/g," }}]").replace(/^model\./,"");
35+
path = $interpolate(path)(context);
2436
sfSelect(path, scope.model, ngModel.$modelValue);
2537
});
2638
});
2739
};
28-
2940
// Validate against the schema.
3041

3142
var validate = function(viewValue, triggered) {

src/schema-form.module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ angular
6262
.directive('sfSchema', [ '$compile', '$http', '$templateCache', '$q', 'schemaForm',
6363
'schemaFormDecorators', 'sfSelect', 'sfPath', 'sfBuilder',
6464
sfSchemaDirective ])
65-
.directive('schemaValidate', [ 'sfValidator', '$parse', 'sfSelect', schemaValidateDirective ])
65+
.directive('schemaValidate', [ 'sfValidator', '$parse', 'sfSelect', '$interpolate', schemaValidateDirective ])
6666
.directive('sfKeyController', [ 'schemaForm','sfPath', sfKeyDirective ]);

0 commit comments

Comments
 (0)