diff --git a/src/directives/schema-form.js b/src/directives/schema-form.js index 3efa8e3aa..d42f93148 100644 --- a/src/directives/schema-form.js +++ b/src/directives/schema-form.js @@ -108,12 +108,14 @@ angular.module('schemaForm') scope.$emit('sf-render-finished', element); }; + var defaultForm = ['*']; + //Since we are dependant on up to three //attributes we'll do a common watch scope.$watch(function() { var schema = scope.schema; - var form = scope.initialForm || ['*']; + var form = scope.initialForm || defaultForm; //The check for schema.type is to ensure that schema is not {} if (form && schema && schema.type && diff --git a/test/directives/schema-form-test.js b/test/directives/schema-form-test.js index 049c670ee..cbbb64d28 100644 --- a/test/directives/schema-form-test.js +++ b/test/directives/schema-form-test.js @@ -56,6 +56,32 @@ describe('directive',function(){ }); }); + it('should generate html and compile when no form is provided, using the default',function(){ + + inject(function($compile,$rootScope){ + var scope = $rootScope.$new(); + scope.person = {}; + + scope.schema = exampleSchema; + + scope.form = undefined; + + var tmpl = angular.element('
'); + + $compile(tmpl)(scope); + $rootScope.$apply(); + + tmpl.children().length.should.be.equal(2); + tmpl.children().eq(0).is('bootstrap-decorator').should.be.true; + tmpl.children().eq(0).children().eq(0).is('div.form-group').should.be.true; + tmpl.children().eq(0).children().eq(0).find('input').is('input[type="text"]').should.be.true; + tmpl.children().eq(0).children().eq(0).find('input').attr('ng-model').should.be.equal('model[\'name\']'); + tmpl.children().eq(1).children().eq(0).is('div.form-group').should.be.true; + tmpl.children().eq(1).children().eq(0).children('select').length.should.equal(1); + + }); + }); + it('should generate html and compile it, deep structure',function(){ inject(function($compile,$rootScope){