From 316f53e8557223010dec9b4900335b496215867f Mon Sep 17 00:00:00 2001 From: Kenny Sabir Date: Fri, 2 Dec 2016 13:45:33 +1100 Subject: [PATCH] adding raw template to decorator --- src/services/builder.js | 4 ++-- test/services/decorators-test.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/services/builder.js b/src/services/builder.js index f8c46dba3..49088db26 100644 --- a/src/services/builder.js +++ b/src/services/builder.js @@ -277,8 +277,8 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s */ build: function(form, decorator, slots, lookup) { return build(form, decorator, function(form, field) { - if (form.type === 'template') { - return form.template; + if (field.type === 'template') { + return field.template; } return $templateCache.get(field.template); }, slots, undefined, undefined, lookup); diff --git a/test/services/decorators-test.js b/test/services/decorators-test.js index cab6e77fa..e694c504b 100644 --- a/test/services/decorators-test.js +++ b/test/services/decorators-test.js @@ -16,6 +16,30 @@ describe('schemaFormDecorators', function() { var templateWithWrap = angular.element('
'); var template = templateWithWrap.children().eq(0); + $compile(template)($rootScope); + $rootScope.$apply(); + templateWithWrap.children().length.should.equal(1); + templateWithWrap.children().is('foobar').should.be.true; + templateWithWrap.children().eq(0).children().length.should.equal(1); + templateWithWrap.children().eq(0).children().is('div').should.be.true; + templateWithWrap.children().eq(0).children().hasClass('yes').should.be.true; + }); + }); + }); + describe('#createDecoratorWithRawTemplate', function() { + it('should enable you to create new decorator directives',function(){ + module(function(schemaFormDecoratorsProvider){ + schemaFormDecoratorsProvider.defineDecorator('foobar',{ + 'foo': {template: '
YES
', replace: true, type: 'template'} + },[angular.noop]); + }); + + inject(function($rootScope,$compile){ + + //Since our directive does a replace we need a wrapper to actually check the content. + var templateWithWrap = angular.element('
'); + var template = templateWithWrap.children().eq(0); + $compile(template)($rootScope); $rootScope.$apply(); templateWithWrap.children().length.should.equal(1);