@@ -9,11 +9,15 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
9
9
return ( pos ? separator : '' ) + letter . toLowerCase ( ) ;
10
10
} ) ;
11
11
} ;
12
+ var formId = 0 ;
12
13
13
14
var builders = {
14
15
sfField : function ( args ) {
15
- args . fieldFrag . firstChild . setAttribute ( 'sf-field' , args . path ) ;
16
- angular . element . data ( args . fieldFrag . firstChild , 'sfForm' , args . form ) ;
16
+ args . fieldFrag . firstChild . setAttribute ( 'sf-field' , formId ) ;
17
+
18
+ // We use a lookup table for easy access to our form.
19
+ args . lookup [ 'f' + formId ] = args . form ;
20
+ formId ++ ;
17
21
} ,
18
22
ngModel : function ( args ) {
19
23
if ( ! args . form . key ) {
@@ -117,8 +121,9 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
117
121
}
118
122
} ;
119
123
120
- var build = function ( items , decorator , templateFn , slots , path , state ) {
124
+ var build = function ( items , decorator , templateFn , slots , path , state , lookup ) {
121
125
state = state || { } ;
126
+ lookup = lookup || Object . create ( null ) ;
122
127
path = path || 'schemaForm.form' ;
123
128
var container = document . createDocumentFragment ( ) ;
124
129
items . reduce ( function ( frag , f , index ) {
@@ -155,12 +160,13 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
155
160
var args = {
156
161
fieldFrag : tmpl ,
157
162
form : f ,
163
+ lookup : lookup ,
158
164
state : state ,
159
165
path : path + '[' + index + ']' ,
160
166
161
167
// Recursive build fn
162
168
build : function ( items , path , state ) {
163
- return build ( items , decorator , templateFn , slots , path , state ) ;
169
+ return build ( items , decorator , templateFn , slots , path , state , lookup ) ;
164
170
} ,
165
171
166
172
} ;
@@ -185,10 +191,10 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
185
191
/**
186
192
* Builds a form from a canonical form definition
187
193
*/
188
- build : function ( form , decorator , slots ) {
194
+ build : function ( form , decorator , slots , lookup ) {
189
195
return build ( form , decorator , function ( url ) {
190
196
return $templateCache . get ( url ) ;
191
- } , slots ) ;
197
+ } , slots , undefined , undefined , lookup ) ;
192
198
193
199
} ,
194
200
builder : builders ,
0 commit comments