Permalink
Browse files

Merge pull request #725 from jozefizso/fix/templates_nodes

Add support for templates with leading whitespaces
  • Loading branch information...
2 parents b703975 + e4d2e61 commit c372baed285fd5d613fbae7ebed30648585d0964 @Anthropic Anthropic committed on GitHub Jul 10, 2016
Showing with 40 additions and 1 deletion.
  1. +11 −1 src/services/builder.js
  2. +29 −0 test/directives/schema-form-test.js
@@ -11,9 +11,19 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
};
var formId = 0;
+ if (!("firstElementChild" in document.createDocumentFragment())) {
+ Object.defineProperty(DocumentFragment.prototype, "firstElementChild", {
+ get: function () {
+ for (var nodes = this.childNodes, n, i = 0, l = nodes.length; i < l; ++i)
+ if (n = nodes[i], 1 === n.nodeType) return n;
+ return null;
+ }
+ });
+ }
+
var builders = {
sfField: function(args) {
- args.fieldFrag.firstChild.setAttribute('sf-field', formId);
+ args.fieldFrag.firstElementChild.setAttribute('sf-field', formId);
// We use a lookup table for easy access to our form.
args.lookup['f' + formId] = args.form;
@@ -1902,6 +1902,35 @@ describe('directive',function(){
});
});
+ it('should use supplied template with leading whitespace in template field',function() {
+
+ inject(function($compile, $rootScope){
+ var scope = $rootScope.$new();
+ scope.person = {};
+
+ scope.schema = {
+ type: 'object',
+ properties: {
+ name: {type: 'string'}
+ }
+ };
+
+ scope.form = [
+ {
+ type: 'template',
+ template: ' <div>{{form.foo}}</div>',
+ foo: "Hello World"
+ }
+ ];
+
+ var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="person"></form>');
+
+ $compile(tmpl)(scope);
+ $rootScope.$apply();
+ tmpl.html().should.be.eq(' <div sf-field="0" class="ng-scope ng-binding">Hello World</div>');
+ });
+ });
+
it('should load template by templateUrl, with template field type',function() {
inject(function($compile, $rootScope, $httpBackend){

0 comments on commit c372bae

Please sign in to comment.