Skip to content

Commit 01ba883

Browse files
committed
Completed fix for #750
1 parent 40c254e commit 01ba883

7 files changed

+84
-58
lines changed

dist/angular-schema-form-bootstrap.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-schema-form
3-
* @version 1.0.0-alpha.3
4-
* @date Sun, 02 Apr 2017 13:11:29 GMT
3+
* @version 1.0.0-alpha.4
4+
* @date Mon, 03 Apr 2017 12:57:37 GMT
55
* @link https://github.com/json-schema-form/angular-schema-form
66
* @license MIT
77
* Copyright (c) 2014-2017 JSON Schema Form
@@ -92,8 +92,8 @@ module.exports = __webpack_require__(3);
9292

9393
/*!
9494
* angular-schema-form-bootstrap
95-
* @version 1.0.0-alpha.3
96-
* @date Sun, 02 Apr 2017 13:11:20 GMT
95+
* @version 1.0.0-alpha.4
96+
* @date Sun, 02 Apr 2017 13:57:49 GMT
9797
* @link https://github.com/json-schema-form/angular-schema-form-bootstrap
9898
* @license MIT
9999
* Copyright (c) 2014-2017 JSON Schema Form
@@ -201,7 +201,7 @@ module.exports = __webpack_require__(3);
201201
/***/function (module, exports) {
202202

203203
var path = '/bootstrap/array.html';
204-
var html = "<div class=\"schema-form-array {{::form.htmlClass + ' ' + idClass}}\"\r\n sf-field-model=\"sf-new-array\"\r\n sf-new-array>\r\n <label class=\"control-label\" ng-show=\"showTitle()\">{{ form.title }}</label>\r\n <ol class=\"list-group\" sf-field-model ui-sortable=\"form.sortOptions\">\r\n <li class=\"list-group-item {{::form.fieldHtmlClass}}\"\r\n sf-field-model=\"ng-repeat\"\r\n ng-repeat=\"item in $$value$$ track by $id(item)\">\r\n <button ng-hide=\"form.readonly || form.remove === null\"\r\n ng-click=\"deleteFromArray($index)\"\r\n ng-disabled=\"form.schema.minItems >= modelArray.length\"\r\n style=\"position: relative; z-index: 20;\"\r\n type=\"button\" class=\"close pull-right\">\r\n <span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span>\r\n </button>\r\n <div schema-form-array-items sf-key-controller sf-parent-key=\"[{{form.key.join('][')}}]\" sf-index=\"{{$index}}\"></div>\r\n </li>\r\n </ol>\r\n <div class=\"clearfix\" style=\"padding: 15px;\" ng-model=\"modelArray\" schema-validate=\"form\">\r\n <div class=\"help-block\"\r\n ng-show=\"(hasError() && errorMessage(schemaError())) || form.description\"\r\n ng-bind-html=\"(hasError() && errorMessage(schemaError())) || form.description\"></div>\r\n\r\n <button ng-hide=\"form.readonly || form.add === null\"\r\n ng-click=\"appendToArray()\"\r\n ng-disabled=\"form.schema.maxItems <= modelArray.length\"\r\n type=\"button\"\r\n class=\"btn {{ form.style.add || 'btn-default' }} pull-right\">\r\n <i class=\"glyphicon glyphicon-plus\"></i>\r\n {{ form.add || 'Add'}}\r\n </button>\r\n </div>\r\n</div>\r\n";
204+
var html = "<div class=\"schema-form-array {{::form.htmlClass + ' ' + idClass}}\"\r\n sf-field-model=\"sf-new-array\"\r\n sf-new-array>\r\n <label class=\"control-label\" ng-show=\"showTitle()\">{{ form.title }}</label>\r\n <ol class=\"list-group\" sf-field-model ui-sortable=\"form.sortOptions\">\r\n <li class=\"list-group-item {{::form.fieldHtmlClass}}\"\r\n sf-field-model=\"ng-repeat\"\r\n ng-repeat=\"item in $$value$$ track by $id(trackBy(item, $index))\">\r\n <button ng-hide=\"form.readonly || form.remove === null\"\r\n ng-click=\"deleteFromArray(item)\"\r\n ng-disabled=\"form.schema.minItems >= modelArray.length\"\r\n style=\"position: relative; z-index: 20;\"\r\n type=\"button\" class=\"close pull-right\">\r\n <span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span>\r\n </button>\r\n <div schema-form-array-items sf-key-controller sf-parent-key=\"[{{form.key.join('][')}}]\" sf-index=\"{{$index}}\"></div>\r\n </li>\r\n </ol>\r\n <div class=\"clearfix\" style=\"padding: 15px;\" ng-model=\"modelArray\" schema-validate=\"form\">\r\n <div class=\"help-block\"\r\n ng-show=\"(hasError() && errorMessage(schemaError())) || form.description\"\r\n ng-bind-html=\"(hasError() && errorMessage(schemaError())) || form.description\"></div>\r\n\r\n <button ng-hide=\"form.readonly || form.add === null\"\r\n ng-click=\"appendToArray()\"\r\n ng-disabled=\"form.schema.maxItems <= modelArray.length\"\r\n type=\"button\"\r\n class=\"btn {{ form.style.add || 'btn-default' }} pull-right\">\r\n <i class=\"glyphicon glyphicon-plus\"></i>\r\n {{ form.add || 'Add'}}\r\n </button>\r\n </div>\r\n</div>\r\n";
205205
window.angular.module('ng').run(['$templateCache', function (c) {
206206
c.put(path, html);
207207
}]);

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

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

dist/angular-schema-form.js

+52-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-schema-form
3-
* @version 1.0.0-alpha.3
4-
* @date Sun, 02 Apr 2017 13:11:29 GMT
3+
* @version 1.0.0-alpha.4
4+
* @date Mon, 03 Apr 2017 12:57:49 GMT
55
* @link https://github.com/json-schema-form/angular-schema-form
66
* @license MIT
77
* Copyright (c) 2014-2017 JSON Schema Form
@@ -71,7 +71,7 @@
7171
/******/ __webpack_require__.p = "";
7272
/******/
7373
/******/ // Load entry module and return exports
74-
/******/ return __webpack_require__(__webpack_require__.s = 21);
74+
/******/ return __webpack_require__(__webpack_require__.s = 19);
7575
/******/ })
7676
/************************************************************************/
7777
/******/ ([
@@ -2729,7 +2729,7 @@ module.exports = __webpack_require__(4);
27292729
/***/ })
27302730
/******/ ]);
27312731
//# sourceMappingURL=json-schema-form-core.js.map
2732-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(19).setImmediate))
2732+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(18).setImmediate))
27332733

27342734
/***/ }),
27352735
/* 2 */
@@ -2759,8 +2759,7 @@ module.exports = g;
27592759

27602760

27612761
/***/ }),
2762-
/* 3 */,
2763-
/* 4 */
2762+
/* 3 */
27642763
/***/ (function(module, __webpack_exports__, __webpack_require__) {
27652764

27662765
"use strict";
@@ -2769,18 +2768,18 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
27692768
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_json_schema_form_core___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_json_schema_form_core__);
27702769
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_angular__ = __webpack_require__(0);
27712770
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_angular___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_angular__);
2772-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_sf_builder_provider__ = __webpack_require__(14);
2773-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_schema_form_decorators_provider__ = __webpack_require__(12);
2774-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_schema_form_provider__ = __webpack_require__(13);
2775-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_sf_error_message_provider__ = __webpack_require__(15);
2776-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_sf_path_provider__ = __webpack_require__(16);
2777-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_sf_changed_directive__ = __webpack_require__(7);
2778-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_sf_field_directive__ = __webpack_require__(8);
2779-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_sf_message_directive__ = __webpack_require__(10);
2780-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_10_sf_array_directive__ = __webpack_require__(6);
2781-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_11_sf_key_directive__ = __webpack_require__(9);
2782-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_12_sf_schema_directive__ = __webpack_require__(11);
2783-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_13_schema_validate_directive__ = __webpack_require__(5);
2771+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_sf_builder_provider__ = __webpack_require__(13);
2772+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_schema_form_decorators_provider__ = __webpack_require__(11);
2773+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_schema_form_provider__ = __webpack_require__(12);
2774+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_sf_error_message_provider__ = __webpack_require__(14);
2775+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_sf_path_provider__ = __webpack_require__(15);
2776+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_sf_changed_directive__ = __webpack_require__(6);
2777+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_sf_field_directive__ = __webpack_require__(7);
2778+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_sf_message_directive__ = __webpack_require__(9);
2779+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_10_sf_array_directive__ = __webpack_require__(5);
2780+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_11_sf_key_directive__ = __webpack_require__(8);
2781+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_12_sf_schema_directive__ = __webpack_require__(10);
2782+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_13_schema_validate_directive__ = __webpack_require__(4);
27842783

27852784

27862785

@@ -2834,7 +2833,7 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
28342833
.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 */]]);
28352834

28362835
/***/ }),
2837-
/* 5 */
2836+
/* 4 */
28382837
/***/ (function(module, __webpack_exports__, __webpack_require__) {
28392838

28402839
"use strict";
@@ -3024,12 +3023,14 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
30243023
};
30253024

30263025
/***/ }),
3027-
/* 6 */
3026+
/* 5 */
30283027
/***/ (function(module, __webpack_exports__, __webpack_require__) {
30293028

30303029
"use strict";
30313030
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_angular__ = __webpack_require__(0);
30323031
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_angular___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_angular__);
3032+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
3033+
30333034

30343035

30353036
/**
@@ -3044,6 +3045,11 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
30443045
link: function link(scope, element, attrs) {
30453046
scope.min = 0;
30463047

3048+
scope.trackBy = function (item, index) {
3049+
if (item && (typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object') return item;
3050+
return index;
3051+
};
3052+
30473053
scope.modelArray = scope.$eval(attrs.sfNewArray);
30483054

30493055
// We need to have a ngModel to hook into validation. It doesn't really play well with
@@ -3201,11 +3207,17 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
32013207
return model;
32023208
};
32033209

3204-
scope.deleteFromArray = function (index) {
3210+
scope.deleteFromArray = function (item) {
3211+
var index = scope.modelArray.indexOf(item);
32053212
var model = scope.modelArray;
32063213
if (model) {
32073214
model.splice(index, 1);
32083215
}
3216+
3217+
if (item.$$hashKey) {
3218+
scope.destroyed = item.$$hashKey;
3219+
}
3220+
32093221
return model;
32103222
};
32113223

@@ -3255,7 +3267,7 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
32553267
};
32563268

32573269
/***/ }),
3258-
/* 7 */
3270+
/* 6 */
32593271
/***/ (function(module, __webpack_exports__, __webpack_require__) {
32603272

32613273
"use strict";
@@ -3301,7 +3313,7 @@ __WEBPACK_IMPORTED_MODULE_1_angular___default.a.module('schemaForm', deps)
33013313
};
33023314

33033315
/***/ }),
3304-
/* 8 */
3316+
/* 7 */
33053317
/***/ (function(module, __webpack_exports__, __webpack_require__) {
33063318

33073319
"use strict";
@@ -3586,9 +3598,10 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
35863598
// in the form definition.
35873599
scope.$on('$destroy', function () {
35883600
var key = scope.getKey();
3601+
var arrayIndex = typeof scope.arrayIndex == 'number' ? scope.arrayIndex + 1 : 0;
35893602

35903603
// If the entire schema form is destroyed we don't touch the model
3591-
if (!scope.externalDestructionInProgress) {
3604+
if (!scope.externalDestructionInProgress && (!scope.model.$$hashKey || scope.model.$$hashKey === scope.destroyed)) {
35923605
var destroyStrategy = form.destroyStrategy || scope.options && scope.options.destroyStrategy || 'remove';
35933606
// No key no model, and we might have strategy 'retain'
35943607
if (key && destroyStrategy !== 'retain') {
@@ -3630,7 +3643,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
36303643
};
36313644

36323645
/***/ }),
3633-
/* 9 */
3646+
/* 8 */
36343647
/***/ (function(module, __webpack_exports__, __webpack_require__) {
36353648

36363649
"use strict";
@@ -3669,7 +3682,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
36693682
};;
36703683

36713684
/***/ }),
3672-
/* 10 */
3685+
/* 9 */
36733686
/***/ (function(module, __webpack_exports__, __webpack_require__) {
36743687

36753688
"use strict";
@@ -3773,7 +3786,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
37733786
};
37743787

37753788
/***/ }),
3776-
/* 11 */
3789+
/* 10 */
37773790
/***/ (function(module, __webpack_exports__, __webpack_require__) {
37783791

37793792
"use strict";
@@ -4003,7 +4016,7 @@ FIXME: real documentation
40034016
};
40044017

40054018
/***/ }),
4006-
/* 12 */
4019+
/* 11 */
40074020
/***/ (function(module, __webpack_exports__, __webpack_require__) {
40084021

40094022
"use strict";
@@ -4546,7 +4559,7 @@ FIXME: real documentation
45464559
};;
45474560

45484561
/***/ }),
4549-
/* 13 */
4562+
/* 12 */
45504563
/***/ (function(module, __webpack_exports__, __webpack_require__) {
45514564

45524565
"use strict";
@@ -4685,7 +4698,7 @@ FIXME: real documentation
46854698
};
46864699

46874700
/***/ }),
4688-
/* 14 */
4701+
/* 13 */
46894702
/***/ (function(module, __webpack_exports__, __webpack_require__) {
46904703

46914704
"use strict";
@@ -5013,7 +5026,7 @@ FIXME: real documentation
50135026
};
50145027

50155028
/***/ }),
5016-
/* 15 */
5029+
/* 14 */
50175030
/***/ (function(module, __webpack_exports__, __webpack_require__) {
50185031

50195032
"use strict";
@@ -5150,7 +5163,7 @@ FIXME: real documentation
51505163
};
51515164

51525165
/***/ }),
5153-
/* 16 */
5166+
/* 15 */
51545167
/***/ (function(module, __webpack_exports__, __webpack_require__) {
51555168

51565169
"use strict";
@@ -5190,7 +5203,7 @@ var sfPathProviderClass = function () {
51905203
/* harmony default export */ __webpack_exports__["a"] = sfPathProviderClass;
51915204

51925205
/***/ }),
5193-
/* 17 */
5206+
/* 16 */
51945207
/***/ (function(module, exports) {
51955208

51965209
// shim for using process in browser
@@ -5376,7 +5389,7 @@ process.umask = function() { return 0; };
53765389

53775390

53785391
/***/ }),
5379-
/* 18 */
5392+
/* 17 */
53805393
/***/ (function(module, exports, __webpack_require__) {
53815394

53825395
/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
@@ -5566,10 +5579,10 @@ process.umask = function() { return 0; };
55665579
attachTo.clearImmediate = clearImmediate;
55675580
}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
55685581

5569-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(17)))
5582+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(16)))
55705583

55715584
/***/ }),
5572-
/* 19 */
5585+
/* 18 */
55735586
/***/ (function(module, exports, __webpack_require__) {
55745587

55755588
var apply = Function.prototype.apply;
@@ -5622,18 +5635,17 @@ exports._unrefActive = exports.active = function(item) {
56225635
};
56235636

56245637
// setimmediate attaches itself to the global object
5625-
__webpack_require__(18);
5638+
__webpack_require__(17);
56265639
exports.setImmediate = setImmediate;
56275640
exports.clearImmediate = clearImmediate;
56285641

56295642

56305643
/***/ }),
5631-
/* 20 */,
5632-
/* 21 */
5644+
/* 19 */
56335645
/***/ (function(module, exports, __webpack_require__) {
56345646

56355647
__webpack_require__(1);
5636-
module.exports = __webpack_require__(4);
5648+
module.exports = __webpack_require__(3);
56375649

56385650

56395651
/***/ })

dist/angular-schema-form.min.js

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

src/directives/sf-array.directive.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export default function(sfSelect, sfPath, schemaForm) {
1212
link: function(scope, element, attrs) {
1313
scope.min = 0;
1414

15+
scope.trackBy = function (item, index) {
16+
if(item && typeof item === 'object') return item;
17+
return index;
18+
}
19+
1520
scope.modelArray = scope.$eval(attrs.sfNewArray);
1621

1722
// We need to have a ngModel to hook into validation. It doesn't really play well with
@@ -170,11 +175,17 @@ export default function(sfSelect, sfPath, schemaForm) {
170175
return model;
171176
};
172177

173-
scope.deleteFromArray = function(index) {
178+
scope.deleteFromArray = function(item) {
179+
var index = scope.modelArray.indexOf(item);
174180
var model = scope.modelArray;
175181
if (model) {
176182
model.splice(index, 1);
177183
}
184+
185+
if(item.$$hashKey) {
186+
scope.destroyed = item.$$hashKey;
187+
}
188+
178189
return model;
179190
};
180191

src/directives/sf-field.directive.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ sfPath, sfSelect) {
292292
// in the form definition.
293293
scope.$on('$destroy', function() {
294294
let key = scope.getKey();
295+
let arrayIndex = (typeof scope.arrayIndex == 'number') ? scope.arrayIndex + 1: 0;
295296

296297
// If the entire schema form is destroyed we don't touch the model
297-
if (!scope.externalDestructionInProgress) {
298+
if (!scope.externalDestructionInProgress &&
299+
(!scope.model.$$hashKey || scope.model.$$hashKey === scope.destroyed)) {
298300
var destroyStrategy = form.destroyStrategy ||
299301
(scope.options && scope.options.destroyStrategy) || 'remove';
300302
// No key no model, and we might have strategy 'retain'

src/directives/sf-schema.directive.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,7 @@ describe('destroy strategy', function() {
25582558
setTimeout(function() {
25592559
scope.person.switch = false;
25602560
scope.$apply();
2561+
25612562
scope.person.should.deep.equal({
25622563
"switch": false
25632564
});

0 commit comments

Comments
 (0)