File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -108,12 +108,14 @@ angular.module('schemaForm')
108108 scope . $emit ( 'sf-render-finished' , element ) ;
109109 } ;
110110
111+ var defaultForm = [ '*' ] ;
112+
111113 //Since we are dependant on up to three
112114 //attributes we'll do a common watch
113115 scope . $watch ( function ( ) {
114116
115117 var schema = scope . schema ;
116- var form = scope . initialForm || [ '*' ] ;
118+ var form = scope . initialForm || defaultForm ;
117119
118120 //The check for schema.type is to ensure that schema is not {}
119121 if ( form && schema && schema . type &&
Original file line number Diff line number Diff line change @@ -56,6 +56,32 @@ describe('directive',function(){
5656 } ) ;
5757 } ) ;
5858
59+ it ( 'should generate html and compile when no form is provided, using the default' , function ( ) {
60+
61+ inject ( function ( $compile , $rootScope ) {
62+ var scope = $rootScope . $new ( ) ;
63+ scope . person = { } ;
64+
65+ scope . schema = exampleSchema ;
66+
67+ scope . form = undefined ;
68+
69+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
70+
71+ $compile ( tmpl ) ( scope ) ;
72+ $rootScope . $apply ( ) ;
73+
74+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
75+ tmpl . children ( ) . eq ( 0 ) . is ( 'bootstrap-decorator' ) . should . be . true ;
76+ tmpl . children ( ) . eq ( 0 ) . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
77+ tmpl . children ( ) . eq ( 0 ) . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
78+ tmpl . children ( ) . eq ( 0 ) . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'ng-model' ) . should . be . equal ( 'model[\'name\']' ) ;
79+ tmpl . children ( ) . eq ( 1 ) . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
80+ tmpl . children ( ) . eq ( 1 ) . children ( ) . eq ( 0 ) . children ( 'select' ) . length . should . equal ( 1 ) ;
81+
82+ } ) ;
83+ } ) ;
84+
5985 it ( 'should generate html and compile it, deep structure' , function ( ) {
6086
6187 inject ( function ( $compile , $rootScope ) {
You can’t perform that action at this time.
0 commit comments