@@ -5,8 +5,8 @@ FIXME: real documentation
55
66angular . module ( 'schemaForm' )
77 . directive ( 'sfSchema' ,
8- [ '$compile' , 'schemaForm' ,
9- function ( $compile , schemaForm ) {
8+ [ '$compile' , 'schemaForm' , 'schemaFormDecorators' ,
9+ function ( $compile , schemaForm , schemaFormDecorators ) {
1010
1111 //recurse through the entire schema.
1212 //FIXME: no support for arrays
@@ -18,7 +18,13 @@ function($compile, schemaForm){
1818 } ) ;
1919 } ;
2020
21-
21+ var SNAKE_CASE_REGEXP = / [ A - Z ] / g;
22+ function snake_case ( name , separator ) {
23+ separator = separator || '_' ;
24+ return name . replace ( SNAKE_CASE_REGEXP , function ( letter , pos ) {
25+ return ( pos ? separator : '' ) + letter . toLowerCase ( ) ;
26+ } ) ;
27+ }
2228
2329 return {
2430 scope : {
@@ -74,11 +80,10 @@ function($compile, schemaForm){
7480
7581 //Create directives from the form definition
7682 angular . forEach ( merged , function ( obj , i ) {
77- var n = document . createElement ( attrs . sfDecorator || 'bootstrap-decorator' ) ;
83+ var n = document . createElement ( attrs . sfDecorator || snake_case ( schemaFormDecorators . defaultDecorator , '-' ) ) ;
7884 n . setAttribute ( 'type' , obj . type ) ;
7985 n . setAttribute ( 'form' , 'schemaForm.form[' + i + ']' ) ;
8086 frag . appendChild ( n ) ;
81-
8287 } ) ;
8388
8489 //clean all but pre existing html.
@@ -87,10 +92,8 @@ function($compile, schemaForm){
8792 element [ 0 ] . appendChild ( frag ) ;
8893
8994 //compile only children
90-
9195 $compile ( element . children ( ) ) ( scope ) ;
9296
93-
9497 //ok, now that that is done let's set any defaults
9598 traverse ( schema , function ( prop , path ) {
9699 //This is probably not so fast, but a simple solution.
0 commit comments