@@ -2293,6 +2293,18 @@ function(sel, sfPath, schemaForm) {
2293
2293
}
2294
2294
} ;
2295
2295
2296
+ // If model is undefined make sure it gets set.
2297
+ var getOrCreateModel = function ( ) {
2298
+ var model = scope . modelArray ;
2299
+ if ( ! model ) {
2300
+ var selection = sfPath . parse ( attrs . sfNewArray ) ;
2301
+ model = [ ] ;
2302
+ sel ( selection , scope , model ) ;
2303
+ scope . modelArray = model ;
2304
+ }
2305
+ return model ;
2306
+ } ;
2307
+
2296
2308
// We need the form definition to make a decision on how we should listen.
2297
2309
var once = scope . $watch ( 'form' , function ( form ) {
2298
2310
if ( ! form ) {
@@ -2363,7 +2375,7 @@ function(sel, sfPath, schemaForm) {
2363
2375
//To get two way binding we also watch our titleMapValues
2364
2376
scope . $watchCollection ( 'titleMapValues' , function ( vals , old ) {
2365
2377
if ( vals && vals !== old ) {
2366
- var arr = scope . modelArray ;
2378
+ var arr = getOrCreateModel ( ) ;
2367
2379
2368
2380
// Apparently the fastest way to clear an array, readable too.
2369
2381
// http://jsperf.com/array-destroy/32
@@ -2392,13 +2404,7 @@ function(sel, sfPath, schemaForm) {
2392
2404
var empty ;
2393
2405
2394
2406
// Create and set an array if needed.
2395
- var model = scope . modelArray ;
2396
- if ( ! model ) {
2397
- var selection = sfPath . parse ( attrs . sfNewArray ) ;
2398
- model = [ ] ;
2399
- sel ( selection , scope , model ) ;
2400
- scope . modelArray = model ;
2401
- }
2407
+ var model = getOrCreateModel ( ) ;
2402
2408
2403
2409
// Same old add empty things to the array hack :(
2404
2410
if ( scope . form && scope . form . schema && scope . form . schema . items ) {
0 commit comments