Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/directives/schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
26 changes: 26 additions & 0 deletions test/directives/schema-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<form sf-schema="schema" sf-form="form" sf-model="person"></form>');

$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){
Expand Down