@@ -159,8 +159,8 @@ angular.module('schemaForm').provider('schemaFormDecorators',
159159
160160 var createDirective = function ( name ) {
161161 $compileProvider . directive ( name ,
162- [ '$parse' , '$compile' , '$http' , '$templateCache' , '$interpolate' , 'sfErrorMessage' ,
163- function ( $parse , $compile , $http , $templateCache , $interpolate , sfErrorMessage ) {
162+ [ '$parse' , '$compile' , '$http' , '$templateCache' , '$interpolate' , '$q' , 'sfErrorMessage' ,
163+ function ( $parse , $compile , $http , $templateCache , $interpolate , $q , sfErrorMessage ) {
164164
165165 return {
166166 restrict : 'AE' ,
@@ -304,14 +304,28 @@ angular.module('schemaForm').provider('schemaFormDecorators',
304304 //ok let's replace that template!
305305 //We do this manually since we need to bind ng-model properly and also
306306 //for fieldsets to recurse properly.
307- var url = templateUrl ( name , form ) ;
308- $http . get ( url , { cache : $templateCache } ) . then ( function ( res ) {
309- var key = form . key ?
310- sfPathProvider . stringify ( form . key ) . replace ( / " / g, '"' ) : '' ;
311- var template = res . data . replace (
312- / \$ \$ v a l u e \$ \$ / g,
313- 'model' + ( key [ 0 ] !== '[' ? '.' : '' ) + key
314- ) ;
307+ var templatePromise ;
308+
309+ // type: "template" is a special case. It can contain a template inline or an url.
310+ // otherwise we find out the url to the template and load them.
311+ if ( form . type === 'template' && form . template ) {
312+ templatePromise = $q . when ( form . template ) ;
313+ } else {
314+ var url = form . type === 'template' ? form . templateUrl : templateUrl ( name , form ) ;
315+ templatePromise = $http . get ( url , { cache : $templateCache } ) . then ( function ( res ) {
316+ return res . data ;
317+ } ) ;
318+ }
319+
320+ templatePromise . then ( function ( template ) {
321+ if ( form . key ) {
322+ var key = form . key ?
323+ sfPathProvider . stringify ( form . key ) . replace ( / " / g, '"' ) : '' ;
324+ template = template . replace (
325+ / \$ \$ v a l u e \$ \$ / g,
326+ 'model' + ( key [ 0 ] !== '[' ? '.' : '' ) + key
327+ ) ;
328+ }
315329 element . html ( template ) ;
316330
317331 // Do we have a condition? Then we slap on an ng-if on all children,
@@ -995,11 +1009,15 @@ angular.module('schemaForm').provider('schemaForm',
9951009 }
9961010
9971011 //extend with std form from schema.
998-
9991012 if ( obj . key ) {
10001013 var strid = sfPathProvider . stringify ( obj . key ) ;
10011014 if ( lookup [ strid ] ) {
1002- obj = angular . extend ( lookup [ strid ] , obj ) ;
1015+ var schemaDefaults = lookup [ strid ] ;
1016+ angular . forEach ( schemaDefaults , function ( value , attr ) {
1017+ if ( obj [ attr ] === undefined ) {
1018+ obj [ attr ] = schemaDefaults [ attr ] ;
1019+ }
1020+ } ) ;
10031021 }
10041022 }
10051023
@@ -1750,6 +1768,28 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele
17501768 return viewValue ;
17511769 } ;
17521770
1771+ // Custom validators, parsers, formatters etc
1772+ if ( typeof form . ngModel === 'function' ) {
1773+ form . ngModel ( ngModel ) ;
1774+ }
1775+
1776+ [ '$parsers' , '$viewChangeListeners' , '$formatters' ] . forEach ( function ( attr ) {
1777+ if ( form [ attr ] && ngModel [ attr ] ) {
1778+ form [ attr ] . forEach ( function ( fn ) {
1779+ ngModel [ attr ] . push ( fn ) ;
1780+ } ) ;
1781+ }
1782+ } ) ;
1783+
1784+ [ '$validators' , '$asyncValidators' ] . forEach ( function ( attr ) {
1785+ // Check if our version of angular has i, i.e. 1.3+
1786+ if ( form [ attr ] && ngModel [ attr ] ) {
1787+ angular . forEach ( form [ attr ] , function ( fn , name ) {
1788+ ngModel [ attr ] [ name ] = fn ;
1789+ } ) ;
1790+ }
1791+ } ) ;
1792+
17531793 // Get in last of the parses so the parsed value has the correct type.
17541794 // We don't use $validators since we like to set different errors depeding tv4 error codes
17551795 ngModel . $parsers . push ( validate ) ;
0 commit comments