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
12 changes: 11 additions & 1 deletion src/services/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/directives/schema-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down