@@ -8,9 +8,13 @@ sfPath, sfSelect) {
8
8
replace : false ,
9
9
transclude : false ,
10
10
scope : true ,
11
- require : '^sfSchema' ,
11
+ require : [ '^sfSchema' , '?^form' , '?^^sfKeyController' ] ,
12
12
link : {
13
- pre : function ( scope , element , attrs , sfSchema ) {
13
+ pre : function ( scope , element , attrs , ctrl ) {
14
+ var sfSchema = ctrl [ 0 ] ;
15
+ var formCtrl = ctrl [ 1 ] ;
16
+ var keyCtrl = ctrl [ 2 ] ;
17
+
14
18
//The ngModelController is used in some templates and
15
19
//is needed for error messages,
16
20
scope . $on ( 'schemaFormPropagateNgModelController' , function ( event , ngModel ) {
@@ -22,12 +26,35 @@ sfPath, sfSelect) {
22
26
// Fetch our form.
23
27
scope . form = sfSchema . lookup [ 'f' + attrs . sfField ] ;
24
28
} ,
25
- post : function ( scope , element , attrs , sfSchema ) {
29
+ post : function ( scope , element , attrs , ctrl ) {
30
+ var sfSchema = ctrl [ 0 ] ;
31
+ var formCtrl = ctrl [ 1 ] ;
32
+ var keyCtrl = ctrl [ 2 ] ;
33
+
26
34
//Keep error prone logic from the template
27
35
scope . showTitle = function ( ) {
28
36
return scope . form && scope . form . notitle !== true && scope . form . title ;
29
37
} ;
30
38
39
+ //Normalise names and ids
40
+ scope . fieldId = function ( prependFormName , omitArrayIndexes ) {
41
+ var key = scope . parentKey || [ ] ;
42
+ if ( scope . form . key ) {
43
+ if ( typeof key [ key . length - 1 ] === 'number' ) {
44
+ var combinedKey = key . concat ( scope . form . key . slice ( - 1 ) ) ;
45
+ var formName = ( prependFormName && formCtrl && formCtrl . $name ) ? formCtrl . $name : undefined ;
46
+ return sfPath . name ( combinedKey , '-' , formName , omitArrayIndexes ) ;
47
+ }
48
+ else {
49
+ var formName = ( prependFormName && formCtrl && formCtrl . $name ) ? formCtrl . $name : undefined ;
50
+ return sfPath . name ( scope . form . key , '-' , formName , omitArrayIndexes ) ;
51
+ }
52
+ }
53
+ else {
54
+ return '' ;
55
+ }
56
+ } ;
57
+
31
58
scope . listToCheckboxValues = function ( list ) {
32
59
var values = { } ;
33
60
angular . forEach ( list , function ( v ) {
@@ -155,6 +182,10 @@ sfPath, sfSelect) {
155
182
) ;
156
183
} ;
157
184
185
+ // append the field-id to the htmlClass
186
+ scope . form . htmlClass = scope . form . htmlClass || '' ;
187
+ scope . form . htmlClass += ( scope . form . htmlClass ? ' ' : '' ) + scope . fieldId ( false , true ) ;
188
+
158
189
var form = scope . form ;
159
190
160
191
// Where there is a key there is probably a ngModel
0 commit comments