1
+ /*!
2
+ * angular-schema-form
3
+ * @version 1.0.0-alpha.1
4
+ * @license MIT
5
+ * Copyright (c) 2016 JSON Schema Form
6
+ */
1
7
( function webpackUniversalModuleDefinition ( root , factory ) {
2
8
if ( typeof exports === 'object' && typeof module === 'object' )
3
9
module . exports = factory ( require ( "angular" ) , require ( "tv4" ) ) ;
@@ -282,7 +288,7 @@ return /******/ (function(modules) { // webpackBootstrap
282
288
if ( args . form . key ) {
283
289
var strKey = sfPathProvider . stringify ( args . form . key ) ;
284
290
evalExpr = 'evalExpr(' + args . path + '.condition,{ model: model, "arrayIndex": $index, ' + '"modelValue": model' + ( strKey [ 0 ] === '[' ? '' : '.' ) + strKey + '})' ;
285
- }
291
+ } ;
286
292
287
293
var children = args . fieldFrag . children || args . fieldFrag . childNodes ;
288
294
for ( var i = 0 ; i < children . length ; i ++ ) {
@@ -295,8 +301,8 @@ return /******/ (function(modules) { // webpackBootstrap
295
301
array : function array ( args ) {
296
302
var items = args . fieldFrag . querySelector ( '[schema-form-array-items]' ) ;
297
303
if ( items ) {
298
- state = angular . copy ( args . state ) ;
299
- state . keyRedaction = state . keyRedaction || 0 ;
304
+ var state = angular . copy ( args . state ) ;
305
+ state . keyRedaction = 0 ;
300
306
state . keyRedaction += args . form . key . length + 1 ;
301
307
302
308
// Special case, an array with just one item in it that is not an object.
@@ -323,7 +329,6 @@ return /******/ (function(modules) { // webpackBootstrap
323
329
this . stdBuilders = stdBuilders ;
324
330
325
331
this . $get = [ '$templateCache' , 'schemaFormDecorators' , 'sfPath' , function ( $templateCache , schemaFormDecorators , sfPath ) {
326
-
327
332
var checkForSlot = function checkForSlot ( form , slots ) {
328
333
// Finally append this field to the frag.
329
334
// Check for slots
@@ -368,8 +373,9 @@ return /******/ (function(modules) { // webpackBootstrap
368
373
state . arrayCompatFlag = false ;
369
374
370
375
// TODO: Create a couple fo testcases, small and large and
371
- // measure optmization. A good start is probably a cache of DOM nodes for a particular
372
- // template that can be cloned instead of using innerHTML
376
+ // measure optmization. A good start is probably a
377
+ // cache of DOM nodes for a particular template
378
+ // that can be cloned instead of using innerHTML
373
379
var div = document . createElement ( 'div' ) ;
374
380
var template = templateFn ( f , field ) || templateFn ( f , decorator [ 'default' ] ) ;
375
381
div . innerHTML = template ;
@@ -822,11 +828,11 @@ return /******/ (function(modules) { // webpackBootstrap
822
828
* @param {string } name directive name (CamelCased)
823
829
* @param {Object } fields, an object that maps "type" => `{ template, builder, replace}`.
824
830
attributes `builder` and `replace` are optional, and replace defaults to true.
825
- `template` should be the key of the template to load and it should be pre-loaded
831
+ `template` should be the key of the template to load and it should be pre-loaded
826
832
in `$templateCache`.
827
- `builder` can be a function or an array of functions. They will be called in
833
+ `builder` can be a function or an array of functions. They will be called in
828
834
the order they are supplied.
829
- `replace` (DEPRECATED) is for backwards compatability. If false the builder
835
+ `replace` (DEPRECATED) is for backwards compatability. If false the builder
830
836
will use the "old" way of building that form field using a <sf-decorator>
831
837
directive.
832
838
*/
@@ -1066,6 +1072,12 @@ return /******/ (function(modules) { // webpackBootstrap
1066
1072
/* 6 */
1067
1073
/***/ function ( module , exports , __webpack_require__ ) {
1068
1074
1075
+ /*!
1076
+ * json-schema-form
1077
+ * @version 1.0.0-alpha.1
1078
+ * @license MIT
1079
+ * Copyright 2016 JSON Schema Form
1080
+ */
1069
1081
( function webpackUniversalModuleDefinition ( root , factory ) {
1070
1082
if ( true )
1071
1083
module . exports = factory ( ) ;
@@ -1277,7 +1289,7 @@ return /******/ (function(modules) { // webpackBootstrap
1277
1289
// Since have to ternary state we need a default
1278
1290
if ( obj . type === 'checkbox' && obj . schema [ 'default' ] === undefined ) {
1279
1291
obj . schema [ 'default' ] = false ;
1280
- }
1292
+ } ;
1281
1293
1282
1294
// Special case: template type with tempplateUrl that's needs to be loaded before rendering
1283
1295
// TODO: this is not a clean solution. Maybe something cleaner can be made when $ref support
@@ -1654,9 +1666,13 @@ return /******/ (function(modules) { // webpackBootstrap
1654
1666
/* Utils */
1655
1667
var stripNullType = function stripNullType ( type ) {
1656
1668
if ( Array . isArray ( type ) && type . length == 2 ) {
1657
- if ( type [ 0 ] === 'null' ) return type [ 1 ] ;
1658
- if ( type [ 1 ] === 'null' ) return type [ 0 ] ;
1659
- }
1669
+ if ( type [ 0 ] === 'null' ) {
1670
+ return type [ 1 ] ;
1671
+ } ;
1672
+ if ( type [ 1 ] === 'null' ) {
1673
+ return type [ 0 ] ;
1674
+ } ;
1675
+ } ;
1660
1676
return type ;
1661
1677
} ;
1662
1678
@@ -1676,8 +1692,12 @@ return /******/ (function(modules) { // webpackBootstrap
1676
1692
var rules = schemaTypes [ stripNullType ( schema . type ) ] ;
1677
1693
if ( rules ) {
1678
1694
var def = void 0 ;
1695
+ // We give each rule a possibility to recurse it's children.
1696
+ var innerDefaultFormDefinition = function innerDefaultFormDefinition ( childName , childSchema , childOptions ) {
1697
+ return defaultFormDefinition ( schemaTypes , childName , childSchema , childOptions ) ;
1698
+ } ;
1679
1699
for ( var i = 0 ; i < rules . length ; i ++ ) {
1680
- def = rules [ i ] ( name , schema , options ) ;
1700
+ def = rules [ i ] ( name , schema , options , innerDefaultFormDefinition ) ;
1681
1701
1682
1702
//first handler in list that actually returns something is our handler!
1683
1703
if ( def ) {
@@ -1744,7 +1764,7 @@ return /******/ (function(modules) { // webpackBootstrap
1744
1764
f . ngModelOptions = f . ngModelOptions || { } ;
1745
1765
1746
1766
return f ;
1747
- }
1767
+ } ;
1748
1768
1749
1769
/*** Schema types to form type mappings, with defaults ***/
1750
1770
function text ( name , schema , options ) {
@@ -1815,14 +1835,15 @@ return /******/ (function(modules) { // webpackBootstrap
1815
1835
}
1816
1836
}
1817
1837
1818
- function fieldset ( name , schema , options ) {
1838
+ function fieldset ( name , schema , options , defaultFormDef ) {
1819
1839
if ( stripNullType ( schema . type ) === 'object' ) {
1820
1840
var _ret = function ( ) {
1821
1841
var f = stdFormObj ( name , schema , options ) ;
1822
1842
f . type = 'fieldset' ;
1823
1843
f . items = [ ] ;
1824
1844
options . lookup [ ( 0 , _sfPath . stringify ) ( options . path ) ] = f ;
1825
1845
1846
+ console . log ( 'fieldset' , f , schema ) ;
1826
1847
//recurse down into properties
1827
1848
if ( schema . properties ) {
1828
1849
Object . keys ( schema . properties ) . forEach ( function ( key ) {
@@ -1832,7 +1853,7 @@ return /******/ (function(modules) { // webpackBootstrap
1832
1853
if ( options . ignore [ ( 0 , _sfPath . stringify ) ( path ) ] !== true ) {
1833
1854
var required = schema . required && schema . required . indexOf ( key ) !== - 1 ;
1834
1855
1835
- var def = defaultFormDefinition ( key , value , {
1856
+ var def = defaultFormDef ( key , value , {
1836
1857
path : path ,
1837
1858
required : required || false ,
1838
1859
lookup : options . lookup ,
@@ -1854,7 +1875,7 @@ return /******/ (function(modules) { // webpackBootstrap
1854
1875
}
1855
1876
}
1856
1877
1857
- function array ( name , schema , options ) {
1878
+ function array ( name , schema , options , defaultFormDef ) {
1858
1879
if ( stripNullType ( schema . type ) === 'array' ) {
1859
1880
var f = stdFormObj ( name , schema , options ) ;
1860
1881
f . type = 'array' ;
@@ -1871,7 +1892,7 @@ return /******/ (function(modules) { // webpackBootstrap
1871
1892
var arrPath = options . path . slice ( ) ;
1872
1893
arrPath . push ( '' ) ;
1873
1894
1874
- f . items = [ defaultFormDefinition ( name , schema . items , {
1895
+ f . items = [ defaultFormDef ( name , schema . items , {
1875
1896
path : arrPath ,
1876
1897
required : required || false ,
1877
1898
lookup : options . lookup ,
@@ -1892,9 +1913,10 @@ return /******/ (function(modules) { // webpackBootstrap
1892
1913
number : [ number ] ,
1893
1914
integer : [ integer ] ,
1894
1915
boolean : [ checkbox ] ,
1895
- array : [ checkboxes , array ]
1916
+ array : [ array ] ,
1917
+ defaultForm : defaultForm
1896
1918
} ;
1897
- }
1919
+ } ;
1898
1920
1899
1921
/**
1900
1922
* Create form defaults from schema
@@ -3474,10 +3496,12 @@ return /******/ (function(modules) { // webpackBootstrap
3474
3496
}
3475
3497
} ;
3476
3498
3499
+ var first = true ;
3477
3500
ngModel . $formatters . push ( function ( val ) {
3478
3501
// When a form first loads this will be called for each field.
3479
3502
// we usually don't want that.
3480
- if ( ngModel . $pristine && scope . firstDigest && ( ! scope . options || scope . options . validateOnRender !== true ) ) {
3503
+ if ( ngModel . $pristine && first && ( ! scope . options || scope . options . validateOnRender !== true ) ) {
3504
+ first = false ;
3481
3505
return val ;
3482
3506
}
3483
3507
validate ( ngModel . $modelValue ) ;
0 commit comments