@@ -2293,6 +2293,18 @@ function(sel, sfPath, schemaForm) {
22932293 }
22942294 } ;
22952295
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+
22962308 // We need the form definition to make a decision on how we should listen.
22972309 var once = scope . $watch ( 'form' , function ( form ) {
22982310 if ( ! form ) {
@@ -2363,7 +2375,7 @@ function(sel, sfPath, schemaForm) {
23632375 //To get two way binding we also watch our titleMapValues
23642376 scope . $watchCollection ( 'titleMapValues' , function ( vals , old ) {
23652377 if ( vals && vals !== old ) {
2366- var arr = scope . modelArray ;
2378+ var arr = getOrCreateModel ( ) ;
23672379
23682380 // Apparently the fastest way to clear an array, readable too.
23692381 // http://jsperf.com/array-destroy/32
@@ -2392,13 +2404,7 @@ function(sel, sfPath, schemaForm) {
23922404 var empty ;
23932405
23942406 // 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 ( ) ;
24022408
24032409 // Same old add empty things to the array hack :(
24042410 if ( scope . form && scope . form . schema && scope . form . schema . items ) {
0 commit comments