@@ -69,14 +69,32 @@ Forms.helpers = {
69
69
}
70
70
// sub-context helpers
71
71
, withField : function ( field , fieldName ) {
72
+
73
+ if ( typeof field == 'string' ) {
74
+ fieldName = field ;
75
+ field = this . get ( 'schema' , fieldName ) ;
76
+ }
77
+
78
+ if ( field instanceof Spacebars . kw ) {
79
+ field = field . hash ;
80
+ this . set ( 'schema' , field . name , field ) ;
81
+ }
82
+
83
+ if ( ! fieldName ) {
84
+ fieldName = field . name ;
85
+ }
86
+
87
+ var fieldDefaults = this . field || { } ;
88
+
72
89
// field represents a schema entry
73
90
return _ . defaults ( {
74
91
fieldName : fieldName
92
+ , fieldDefaults : fieldDefaults
75
93
, field : _ . defaults ( {
76
94
name : fieldName
77
95
}
78
96
, field
79
- , this . field || { }
97
+ , fieldDefaults
80
98
)
81
99
// I think there's no need to allow a field to extend options,
82
100
// options are fundementally form level, you should specify
@@ -93,7 +111,35 @@ Forms.helpers = {
93
111
, withFields : function ( ) {
94
112
return _ . map ( this . schema , this . withField , this ) ;
95
113
}
114
+ , withChild : function ( child ) {
115
+ var field = this . get ( 'field' , true ) ;
116
+ var schema = field . schema || { } ;
117
+ var fieldDefaults = field . field || { } ;
118
+
119
+ return Forms . reactiveContext ( child , {
120
+ schema : schema
121
+ , field : _ . defaults ( { } , fieldDefaults , this . fieldDefaults )
122
+ } , this ) ;
123
+ }
124
+ , withChildren : function ( ) {
125
+ // should be called from inside a withField context
126
+ return _ . map ( this . get ( this . fieldName ) || [ ] , this . withChild , this ) ;
127
+ }
96
128
, withButton : function ( button , buttonName ) {
129
+ if ( typeof button == 'string' ) {
130
+ buttonName = button ;
131
+ button = this . get ( 'buttons' , buttonName ) ;
132
+ }
133
+
134
+ if ( button instanceof Spacebars . kw ) {
135
+ button = button . hash ;
136
+ this . set ( 'buttons' , button . name , button ) ;
137
+ }
138
+
139
+ if ( ! buttonName ) {
140
+ buttonName = button . name ;
141
+ }
142
+
97
143
// button represents a buttons entry
98
144
return _ . defaults ( {
99
145
buttonName : buttonName
0 commit comments