@@ -9,11 +9,15 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
99 return ( pos ? separator : '' ) + letter . toLowerCase ( ) ;
1010 } ) ;
1111 } ;
12+ var formId = 0 ;
1213
1314 var builders = {
1415 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 ++ ;
1721 } ,
1822 ngModel : function ( args ) {
1923 if ( ! args . form . key ) {
@@ -117,8 +121,9 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
117121 }
118122 } ;
119123
120- var build = function ( items , decorator , templateFn , slots , path , state ) {
124+ var build = function ( items , decorator , templateFn , slots , path , state , lookup ) {
121125 state = state || { } ;
126+ lookup = lookup || Object . create ( null ) ;
122127 path = path || 'schemaForm.form' ;
123128 var container = document . createDocumentFragment ( ) ;
124129 items . reduce ( function ( frag , f , index ) {
@@ -155,12 +160,13 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
155160 var args = {
156161 fieldFrag : tmpl ,
157162 form : f ,
163+ lookup : lookup ,
158164 state : state ,
159165 path : path + '[' + index + ']' ,
160166
161167 // Recursive build fn
162168 build : function ( items , path , state ) {
163- return build ( items , decorator , templateFn , slots , path , state ) ;
169+ return build ( items , decorator , templateFn , slots , path , state , lookup ) ;
164170 } ,
165171
166172 } ;
@@ -185,10 +191,10 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
185191 /**
186192 * Builds a form from a canonical form definition
187193 */
188- build : function ( form , decorator , slots ) {
194+ build : function ( form , decorator , slots , lookup ) {
189195 return build ( form , decorator , function ( url ) {
190196 return $templateCache . get ( url ) ;
191- } , slots ) ;
197+ } , slots , undefined , undefined , lookup ) ;
192198
193199 } ,
194200 builder : builders ,
0 commit comments