1
1
/*!
2
- * angular-formly JavaScript Library v7.3.9
2
+ * angular-formly JavaScript Library v8.0.3
3
3
*
4
4
* @license MIT (http://license.angular-formly.com)
5
5
*
@@ -153,7 +153,7 @@ return /******/ (function(modules) { // webpackBootstrap
153
153
154
154
ngModule . constant ( 'formlyApiCheck' , _providersFormlyApiCheck2 [ 'default' ] ) ;
155
155
ngModule . constant ( 'formlyErrorAndWarningsUrlPrefix' , _otherDocsBaseUrl2 [ 'default' ] ) ;
156
- ngModule . constant ( 'formlyVersion' , ( "7.3.9 " ) ) ; // <-- webpack variable
156
+ ngModule . constant ( 'formlyVersion' , ( "8.0.3 " ) ) ; // <-- webpack variable
157
157
158
158
ngModule . provider ( 'formlyUsability' , _providersFormlyUsability2 [ 'default' ] ) ;
159
159
ngModule . provider ( 'formlyConfig' , _providersFormlyConfig2 [ 'default' ] ) ;
@@ -288,6 +288,12 @@ return /******/ (function(modules) { // webpackBootstrap
288
288
message : formlyExpression . optional
289
289
} ) . strict ] ) ) ;
290
290
291
+ var watcherChecker = apiCheck . typeOrArrayOf ( apiCheck . shape ( {
292
+ expression : formlyExpression . optional ,
293
+ listener : formlyExpression . optional ,
294
+ runFieldExpressions : apiCheck . bool . optional
295
+ } ) ) ;
296
+
291
297
var fieldOptionsApiShape = {
292
298
$$hashKey : apiCheck . any . optional ,
293
299
type : apiCheck . shape . ifNot ( [ 'template' , 'templateUrl' ] , apiCheck . string ) . optional ,
@@ -314,10 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap
314
320
getterSetter : apiCheck . bool . optional ,
315
321
timezone : apiCheck . string . optional
316
322
} ) . optional ,
317
- watcher : apiCheck . typeOrArrayOf ( apiCheck . shape ( {
318
- expression : formlyExpression . optional ,
319
- listener : formlyExpression
320
- } ) ) . optional ,
323
+ watcher : watcherChecker . optional ,
321
324
validators : validatorChecker . optional ,
322
325
asyncValidators : validatorChecker . optional ,
323
326
parsers : apiCheck . arrayOf ( formlyExpression ) . optional ,
@@ -360,6 +363,8 @@ return /******/ (function(modules) { // webpackBootstrap
360
363
updateInitialValue : apiCheck . func . optional ,
361
364
removeChromeAutoComplete : apiCheck . bool . optional ,
362
365
templateManipulators : templateManipulators . optional ,
366
+ manualModelWatcher : apiCheck . oneOfType ( [ apiCheck . bool , apiCheck . func ] ) . optional ,
367
+ watchAllExpressions : apiCheck . bool . optional ,
363
368
wrapper : specifyWrapperType . optional ,
364
369
fieldTransform : apiCheck . oneOfType ( [ apiCheck . func , apiCheck . array ] ) . optional ,
365
370
data : apiCheck . object . optional
@@ -374,6 +379,7 @@ return /******/ (function(modules) { // webpackBootstrap
374
379
options : formOptionsApi . optional ,
375
380
templateOptions : apiCheck . object . optional ,
376
381
wrapper : specifyWrapperType . optional ,
382
+ watcher : watcherChecker . optional ,
377
383
hide : apiCheck . bool . optional ,
378
384
hideExpression : formlyExpression . optional ,
379
385
data : apiCheck . object . optional ,
@@ -424,7 +430,7 @@ return /******/ (function(modules) { // webpackBootstrap
424
430
Object . defineProperty ( exports , "__esModule" , {
425
431
value : true
426
432
} ) ;
427
- exports [ "default" ] = "https://github.com/formly-js/angular-formly/blob/" + ( "7.3.9 " ) + "/other/ERRORS_AND_WARNINGS.md#" ;
433
+ exports [ "default" ] = "https://github.com/formly-js/angular-formly/blob/" + ( "8.0.3 " ) + "/other/ERRORS_AND_WARNINGS.md#" ;
428
434
module . exports = exports [ "default" ] ;
429
435
430
436
/***/ } ,
@@ -1232,7 +1238,7 @@ return /******/ (function(modules) { // webpackBootstrap
1232
1238
1233
1239
// @ngInject
1234
1240
function FormlyFieldController ( $scope , $timeout , $parse , $controller , formlyValidationMessages ) {
1235
- /* eslint max-statements:[2, 32 ] */
1241
+ /* eslint max-statements:[2, 34 ] */
1236
1242
if ( $scope . options . fieldGroup ) {
1237
1243
setupFieldGroup ( ) ;
1238
1244
return ;
@@ -1250,6 +1256,7 @@ return /******/ (function(modules) { // webpackBootstrap
1250
1256
setDefaultValue ( ) ;
1251
1257
setInitialValue ( ) ;
1252
1258
runExpressions ( ) ;
1259
+ watchExpressions ( ) ;
1253
1260
addValidationMessages ( $scope . options ) ;
1254
1261
invokeControllers ( $scope , $scope . options , fieldType ) ;
1255
1262
@@ -1269,6 +1276,23 @@ return /******/ (function(modules) { // webpackBootstrap
1269
1276
} , 0 , false ) ;
1270
1277
}
1271
1278
1279
+ function watchExpressions ( ) {
1280
+ if ( $scope . formOptions . watchAllExpressions ) {
1281
+ ( function ( ) {
1282
+ var field = $scope . options ;
1283
+ var currentValue = valueGetterSetter ( ) ;
1284
+ _angularFix2 [ 'default' ] . forEach ( field . expressionProperties , function watchExpression ( expression , prop ) {
1285
+ var setter = $parse ( prop ) . assign ;
1286
+ $scope . $watch ( function expressionPropertyWatcher ( ) {
1287
+ return formlyUtil . formlyEval ( $scope , expression , currentValue , currentValue ) ;
1288
+ } , function expressionPropertyListener ( value ) {
1289
+ setter ( field , value ) ;
1290
+ } , true ) ;
1291
+ } ) ;
1292
+ } ) ( ) ;
1293
+ }
1294
+ }
1295
+
1272
1296
function valueGetterSetter ( newVal ) {
1273
1297
if ( ! $scope . model || ! $scope . options . key ) {
1274
1298
return undefined ;
@@ -1771,7 +1795,7 @@ return /******/ (function(modules) { // webpackBootstrap
1771
1795
if ( ! isUrl ) {
1772
1796
return templatePromise ;
1773
1797
} else {
1774
- var _ret2 = ( function ( ) {
1798
+ var _ret3 = ( function ( ) {
1775
1799
var httpOptions = { cache : $templateCache } ;
1776
1800
return {
1777
1801
v : templatePromise . then ( function ( url ) {
@@ -1784,7 +1808,7 @@ return /******/ (function(modules) { // webpackBootstrap
1784
1808
} ;
1785
1809
} ) ( ) ;
1786
1810
1787
- if ( typeof _ret2 === 'object' ) return _ret2 . v ;
1811
+ if ( typeof _ret3 === 'object' ) return _ret3 . v ;
1788
1812
}
1789
1813
}
1790
1814
@@ -2030,7 +2054,7 @@ return /******/ (function(modules) { // webpackBootstrap
2030
2054
if ( attrs . hasOwnProperty ( 'isFieldGroup' ) && el . parent ( ) . parent ( ) . hasClass ( 'formly' ) ) {
2031
2055
parentFormAttributes = copyAttributes ( el . parent ( ) . parent ( ) [ 0 ] . attributes ) ;
2032
2056
}
2033
- return '\n <' + rootEl + ' class="formly"\n name="' + getFormName ( ) + '"\n role="form" ' + parentFormAttributes + '>\n <' + fieldRootEl + ' formly-field\n ng-repeat="field in fields ' + getTrackBy ( ) + '"\n ' + getHideDirective ( ) + '="!field.hide"\n class="formly-field"\n options="field"\n model="field.model || model "\n original-model="model"\n fields="fields"\n form="theFormlyForm"\n form-id="' + getFormName ( ) + '"\n form-state="options.formState"\n form-options="options"\n index="$index">\n </' + fieldRootEl + '>\n <div ng-transclude class="' + getTranscludeClass ( ) + '"></div>\n </' + rootEl + '>\n ' ;
2057
+ return '\n <' + rootEl + ' class="formly"\n name="' + getFormName ( ) + '"\n role="form" ' + parentFormAttributes + '>\n <' + fieldRootEl + ' formly-field\n ng-repeat="field in fields ' + getTrackBy ( ) + '"\n ' + getHideDirective ( ) + '="!field.hide"\n class="formly-field"\n options="field"\n model="field.model"\n original-model="model"\n fields="fields"\n form="theFormlyForm"\n form-id="' + getFormName ( ) + '"\n form-state="options.formState"\n form-options="options"\n index="$index">\n </' + fieldRootEl + '>\n <div ng-transclude class="' + getTranscludeClass ( ) + '"></div>\n </' + rootEl + '>\n ' ;
2034
2058
2035
2059
function getRootEl ( ) {
2036
2060
return attrs . rootEl || 'ng-form' ;
@@ -2091,29 +2115,46 @@ return /******/ (function(modules) { // webpackBootstrap
2091
2115
setupFields ( ) ;
2092
2116
2093
2117
// watch the model and evaluate watch expressions that depend on it.
2094
- $scope . $watch ( 'model' , onModelOrFormStateChange , true ) ;
2118
+ if ( ! $scope . options . manualModelWatcher ) {
2119
+ $scope . $watch ( 'model' , onModelOrFormStateChange , true ) ;
2120
+ } else if ( _angularFix2 [ 'default' ] . isFunction ( $scope . options . manualModelWatcher ) ) {
2121
+ $scope . $watch ( $scope . options . manualModelWatcher , onModelOrFormStateChange , true ) ;
2122
+ }
2123
+
2095
2124
if ( $scope . options . formState ) {
2096
2125
$scope . $watch ( 'options.formState' , onModelOrFormStateChange , true ) ;
2097
2126
}
2098
2127
2099
2128
function onModelOrFormStateChange ( ) {
2100
- _angularFix2 [ 'default' ] . forEach ( $scope . fields , function runFieldExpressionProperties ( field , index ) {
2101
- var model = field . model || $scope . model ;
2102
- var promise = field . runExpressions && field . runExpressions ( ) ;
2103
- if ( field . hideExpression ) {
2104
- // can't use hide with expressionProperties reliably
2105
- var val = model [ field . key ] ;
2106
- field . hide = evalCloseToFormlyExpression ( field . hideExpression , val , field , index ) ;
2107
- }
2108
- if ( field . extras && field . extras . validateOnModelChange && field . formControl ) {
2109
- var validate = field . formControl . $validate ;
2110
- if ( promise ) {
2111
- promise . then ( validate ) ;
2112
- } else {
2113
- validate ( ) ;
2114
- }
2129
+ _angularFix2 [ 'default' ] . forEach ( $scope . fields , runFieldExpressionProperties ) ;
2130
+ }
2131
+
2132
+ function validateFormControl ( formControl , promise ) {
2133
+ var validate = formControl . $validate ;
2134
+ if ( promise ) {
2135
+ promise . then ( validate ) ;
2136
+ } else {
2137
+ validate ( ) ;
2138
+ }
2139
+ }
2140
+
2141
+ function runFieldExpressionProperties ( field , index ) {
2142
+ var model = field . model || $scope . model ;
2143
+ var promise = field . runExpressions && field . runExpressions ( ) ;
2144
+ if ( field . hideExpression ) {
2145
+ // can't use hide with expressionProperties reliably
2146
+ var val = model [ field . key ] ;
2147
+ field . hide = evalCloseToFormlyExpression ( field . hideExpression , val , field , index ) ;
2148
+ }
2149
+ if ( field . extras && field . extras . validateOnModelChange && field . formControl ) {
2150
+ if ( _angularFix2 [ 'default' ] . isArray ( field . formControl ) ) {
2151
+ _angularFix2 [ 'default' ] . forEach ( field . formControl , function ( formControl ) {
2152
+ validateFormControl ( formControl , promise ) ;
2153
+ } ) ;
2154
+ } else {
2155
+ validateFormControl ( field . formControl , promise ) ;
2115
2156
}
2116
- } ) ;
2157
+ }
2117
2158
}
2118
2159
2119
2160
function setupFields ( ) {
@@ -2138,6 +2179,10 @@ return /******/ (function(modules) { // webpackBootstrap
2138
2179
2139
2180
setupModels ( ) ;
2140
2181
2182
+ if ( $scope . options . watchAllExpressions ) {
2183
+ _angularFix2 [ 'default' ] . forEach ( $scope . fields , setupHideExpressionWatcher ) ;
2184
+ }
2185
+
2141
2186
_angularFix2 [ 'default' ] . forEach ( $scope . fields , attachKey ) ; // attaches a key based on the index if a key isn't specified
2142
2187
_angularFix2 [ 'default' ] . forEach ( $scope . fields , setupWatchers ) ; // setup watchers for all fields
2143
2188
}
@@ -2184,6 +2229,8 @@ return /******/ (function(modules) { // webpackBootstrap
2184
2229
function setupModels ( ) {
2185
2230
// a set of field models that are already watched (the $scope.model will have its own watcher)
2186
2231
var watchedModels = [ $scope . model ] ;
2232
+ // we will not set up automatic model watchers if manual mode is set
2233
+ var manualModelWatcher = $scope . options . manualModelWatcher ;
2187
2234
2188
2235
if ( $scope . options . formState ) {
2189
2236
// $scope.options.formState will have its own watcher
@@ -2193,7 +2240,7 @@ return /******/ (function(modules) { // webpackBootstrap
2193
2240
_angularFix2 [ 'default' ] . forEach ( $scope . fields , function ( field ) {
2194
2241
var isNewModel = initModel ( field ) ;
2195
2242
2196
- if ( field . model && isNewModel && watchedModels . indexOf ( field . model ) === - 1 ) {
2243
+ if ( field . model && isNewModel && watchedModels . indexOf ( field . model ) === - 1 && ! manualModelWatcher ) {
2197
2244
$scope . $watch ( function ( ) {
2198
2245
return field . model ;
2199
2246
} , onModelOrFormStateChange , true ) ;
@@ -2202,24 +2249,56 @@ return /******/ (function(modules) { // webpackBootstrap
2202
2249
} ) ;
2203
2250
}
2204
2251
2252
+ function setupHideExpressionWatcher ( field , index ) {
2253
+ if ( field . hideExpression ) {
2254
+ ( function ( ) {
2255
+ // can't use hide with expressionProperties reliably
2256
+ var model = field . model || $scope . model ;
2257
+ $scope . $watch ( function hideExpressionWatcher ( ) {
2258
+ var val = model [ field . key ] ;
2259
+ return evalCloseToFormlyExpression ( field . hideExpression , val , field , index ) ;
2260
+ } , function ( hide ) {
2261
+ return field . hide = hide ;
2262
+ } , true ) ;
2263
+ } ) ( ) ;
2264
+ }
2265
+ }
2266
+
2205
2267
function initModel ( field ) {
2206
2268
var isNewModel = true ;
2207
2269
2208
2270
if ( _angularFix2 [ 'default' ] . isString ( field . model ) ) {
2209
- var expression = field . model ;
2210
- var index = $scope . fields . indexOf ( field ) ;
2271
+ ( function ( ) {
2272
+ var expression = field . model ;
2273
+
2274
+ isNewModel = ! referencesCurrentlyWatchedModel ( expression ) ;
2211
2275
2212
- isNewModel = ! refrencesCurrentlyWatchedModel ( expression ) ;
2276
+ field . model = resolveStringModel ( expression ) ;
2213
2277
2214
- field . model = evalCloseToFormlyExpression ( expression , undefined , field , index ) ;
2215
- if ( ! field . model ) {
2278
+ $scope . $watch ( function ( ) {
2279
+ return resolveStringModel ( expression ) ;
2280
+ } , function ( model ) {
2281
+ return field . model = model ;
2282
+ } ) ;
2283
+ } ) ( ) ;
2284
+ } else if ( ! field . model ) {
2285
+ field . model = $scope . model ;
2286
+ }
2287
+ return isNewModel ;
2288
+
2289
+ function resolveStringModel ( expression ) {
2290
+ var index = $scope . fields . indexOf ( field ) ;
2291
+ var model = evalCloseToFormlyExpression ( expression , undefined , field , index , { model : $scope . model } ) ;
2292
+
2293
+ if ( ! model ) {
2216
2294
throw formlyUsability . getFieldError ( 'field-model-must-be-initialized' , 'Field model must be initialized. When specifying a model as a string for a field, the result of the' + ' expression must have been initialized ahead of time.' , field ) ;
2217
2295
}
2296
+
2297
+ return model ;
2218
2298
}
2219
- return isNewModel ;
2220
2299
}
2221
2300
2222
- function refrencesCurrentlyWatchedModel ( expression ) {
2301
+ function referencesCurrentlyWatchedModel ( expression ) {
2223
2302
return [ 'model' , 'formState' ] . some ( function ( item ) {
2224
2303
return formlyUtil . startsWith ( expression , item + '.' ) || formlyUtil . startsWith ( expression , item + '[' ) ;
2225
2304
} ) ;
@@ -2232,15 +2311,15 @@ return /******/ (function(modules) { // webpackBootstrap
2232
2311
}
2233
2312
2234
2313
function setupWatchers ( field , index ) {
2235
- if ( isFieldGroup ( field ) || ! _angularFix2 [ 'default' ] . isDefined ( field . watcher ) ) {
2314
+ if ( ! _angularFix2 [ 'default' ] . isDefined ( field . watcher ) ) {
2236
2315
return ;
2237
2316
}
2238
2317
var watchers = field . watcher ;
2239
2318
if ( ! _angularFix2 [ 'default' ] . isArray ( watchers ) ) {
2240
2319
watchers = [ watchers ] ;
2241
2320
}
2242
2321
_angularFix2 [ 'default' ] . forEach ( watchers , function setupWatcher ( watcher ) {
2243
- if ( ! _angularFix2 [ 'default' ] . isDefined ( watcher . listener ) ) {
2322
+ if ( ! _angularFix2 [ 'default' ] . isDefined ( watcher . listener ) && ! watcher . runFieldExpressions ) {
2244
2323
throw formlyUsability . getFieldError ( 'all-field-watchers-must-have-a-listener' , 'All field watchers must have a listener' , field ) ;
2245
2324
}
2246
2325
var watchExpression = getWatchExpression ( watcher , field , index ) ;
@@ -2252,7 +2331,12 @@ return /******/ (function(modules) { // webpackBootstrap
2252
2331
}
2253
2332
2254
2333
function getWatchExpression ( watcher , field , index ) {
2255
- var watchExpression = watcher . expression || 'model[\'' + field . key . toString ( ) . split ( '.' ) . join ( '\'][\'' ) + '\']' ;
2334
+ var watchExpression = undefined ;
2335
+ if ( ! _angularFix2 [ 'default' ] . isUndefined ( watcher . expression ) ) {
2336
+ watchExpression = watcher . expression ;
2337
+ } else if ( field . key ) {
2338
+ watchExpression = 'model[\'' + field . key . toString ( ) . split ( '.' ) . join ( '\'][\'' ) + '\']' ;
2339
+ }
2256
2340
if ( _angularFix2 [ 'default' ] . isFunction ( watchExpression ) ) {
2257
2341
( function ( ) {
2258
2342
// wrap the field's watch expression so we can call it with the field as the first arg
@@ -2264,20 +2348,29 @@ return /******/ (function(modules) { // webpackBootstrap
2264
2348
} ;
2265
2349
watchExpression . displayName = 'Formly Watch Expression for field for ' + field . key ;
2266
2350
} ) ( ) ;
2351
+ } else if ( field . model ) {
2352
+ watchExpression = $parse ( watchExpression ) . bind ( null , $scope , { model : field . model } ) ;
2267
2353
}
2268
2354
return watchExpression ;
2269
2355
}
2270
2356
2271
2357
function getWatchListener ( watcher , field , index ) {
2272
2358
var watchListener = watcher . listener ;
2273
- if ( _angularFix2 [ 'default' ] . isFunction ( watchListener ) ) {
2359
+ if ( _angularFix2 [ 'default' ] . isFunction ( watchListener ) || watcher . runFieldExpressions ) {
2274
2360
( function ( ) {
2275
2361
// wrap the field's watch listener so we can call it with the field as the first arg
2276
2362
// and the stop function as the last arg as a helper
2277
2363
var originalListener = watchListener ;
2278
2364
watchListener = function formlyWatchListener ( ) {
2279
- var args = modifyArgs . apply ( undefined , [ watcher , index ] . concat ( _slice . call ( arguments ) ) ) ;
2280
- return originalListener . apply ( undefined , _toConsumableArray ( args ) ) ;
2365
+ var value = undefined ;
2366
+ if ( originalListener ) {
2367
+ var args = modifyArgs . apply ( undefined , [ watcher , index ] . concat ( _slice . call ( arguments ) ) ) ;
2368
+ value = originalListener . apply ( undefined , _toConsumableArray ( args ) ) ;
2369
+ }
2370
+ if ( watcher . runFieldExpressions ) {
2371
+ runFieldExpressionProperties ( field , index ) ;
2372
+ }
2373
+ return value ;
2281
2374
} ;
2282
2375
watchListener . displayName = 'Formly Watch Listener for field for ' + field . key ;
2283
2376
} ) ( ) ;
@@ -2294,16 +2387,21 @@ return /******/ (function(modules) { // webpackBootstrap
2294
2387
}
2295
2388
2296
2389
function evalCloseToFormlyExpression ( expression , val , field , index ) {
2297
- var extraLocals = getFormlyFieldLikeLocals ( field , index ) ;
2390
+ var extraLocals = arguments . length <= 4 || arguments [ 4 ] === undefined ? { } : arguments [ 4 ] ;
2391
+
2392
+ extraLocals = _angularFix2 [ 'default' ] . extend ( getFormlyFieldLikeLocals ( field , index ) , extraLocals ) ;
2298
2393
return formlyUtil . formlyEval ( $scope , expression , val , val , extraLocals ) ;
2299
2394
}
2300
2395
2301
2396
function getFormlyFieldLikeLocals ( field , index ) {
2302
2397
// this makes it closer to what a regular formlyExpression would be
2303
2398
return {
2399
+ model : field . model ,
2304
2400
options : field ,
2305
2401
index : index ,
2306
2402
formState : $scope . options . formState ,
2403
+ originalModel : $scope . model ,
2404
+ formOptions : $scope . options ,
2307
2405
formId : $scope . formId
2308
2406
} ;
2309
2407
}
@@ -2577,7 +2675,7 @@ return /******/ (function(modules) { // webpackBootstrap
2577
2675
var bothBooleanAndBound = [ 'required' , 'disabled' ] ;
2578
2676
var bothAttributeAndBound = [ 'pattern' , 'minlength' ] ;
2579
2677
var statementOnly = [ 'change' , 'keydown' , 'keyup' , 'keypress' , 'click' , 'focus' , 'blur' ] ;
2580
- var attributeOnly = [ 'placeholder' , 'min' , 'max' , 'tabindex' , 'type' ] ;
2678
+ var attributeOnly = [ 'placeholder' , 'min' , 'max' , 'step' , ' tabindex', 'type' ] ;
2581
2679
if ( formlyConfig . extras . ngModelAttrsManipulatorPreferUnbound ) {
2582
2680
bothAttributeAndBound . push ( 'maxlength' ) ;
2583
2681
} else {
0 commit comments