formly.js 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833
  1. /*!
  2. * angular-formly JavaScript Library v0.0.0-semantically-released.0
  3. *
  4. * @license MIT (http://license.angular-formly.com)
  5. *
  6. * built with ♥ by Astrism <astrisms@gmail.com>, Kent C. Dodds <kent@doddsfamily.us>
  7. * (ó ì_í)=óò=(ì_í ò)
  8. */
  9. (function webpackUniversalModuleDefinition(root, factory) {
  10. if(typeof exports === 'object' && typeof module === 'object')
  11. module.exports = factory(require("angular"), require("api-check"));
  12. else if(typeof define === 'function' && define.amd)
  13. define(["angular", "api-check"], factory);
  14. else if(typeof exports === 'object')
  15. exports["ngFormly"] = factory(require("angular"), require("api-check"));
  16. else
  17. root["ngFormly"] = factory(root["angular"], root["apiCheck"]);
  18. })(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_5__) {
  19. return /******/ (function(modules) { // webpackBootstrap
  20. /******/ // The module cache
  21. /******/ var installedModules = {};
  22. /******/ // The require function
  23. /******/ function __webpack_require__(moduleId) {
  24. /******/ // Check if module is in cache
  25. /******/ if(installedModules[moduleId])
  26. /******/ return installedModules[moduleId].exports;
  27. /******/ // Create a new module (and put it into the cache)
  28. /******/ var module = installedModules[moduleId] = {
  29. /******/ exports: {},
  30. /******/ id: moduleId,
  31. /******/ loaded: false
  32. /******/ };
  33. /******/ // Execute the module function
  34. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  35. /******/ // Flag the module as loaded
  36. /******/ module.loaded = true;
  37. /******/ // Return the exports of the module
  38. /******/ return module.exports;
  39. /******/ }
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/ // expose the module cache
  43. /******/ __webpack_require__.c = installedModules;
  44. /******/ // __webpack_public_path__
  45. /******/ __webpack_require__.p = "";
  46. /******/ // Load entry module and return exports
  47. /******/ return __webpack_require__(0);
  48. /******/ })
  49. /************************************************************************/
  50. /******/ ([
  51. /* 0 */
  52. /***/ function(module, exports, __webpack_require__) {
  53. 'use strict';
  54. Object.defineProperty(exports, '__esModule', {
  55. value: true
  56. });
  57. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  58. var _indexCommon = __webpack_require__(1);
  59. var _indexCommon2 = _interopRequireDefault(_indexCommon);
  60. exports['default'] = _indexCommon2['default'];
  61. module.exports = exports['default'];
  62. /***/ },
  63. /* 1 */
  64. /***/ function(module, exports, __webpack_require__) {
  65. 'use strict';
  66. Object.defineProperty(exports, '__esModule', {
  67. value: true
  68. });
  69. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  70. var _angularFix = __webpack_require__(2);
  71. var _angularFix2 = _interopRequireDefault(_angularFix);
  72. var _providersFormlyApiCheck = __webpack_require__(4);
  73. var _providersFormlyApiCheck2 = _interopRequireDefault(_providersFormlyApiCheck);
  74. var _otherDocsBaseUrl = __webpack_require__(6);
  75. var _otherDocsBaseUrl2 = _interopRequireDefault(_otherDocsBaseUrl);
  76. var _providersFormlyUsability = __webpack_require__(7);
  77. var _providersFormlyUsability2 = _interopRequireDefault(_providersFormlyUsability);
  78. var _providersFormlyConfig = __webpack_require__(8);
  79. var _providersFormlyConfig2 = _interopRequireDefault(_providersFormlyConfig);
  80. var _providersFormlyValidationMessages = __webpack_require__(10);
  81. var _providersFormlyValidationMessages2 = _interopRequireDefault(_providersFormlyValidationMessages);
  82. var _servicesFormlyUtil = __webpack_require__(11);
  83. var _servicesFormlyUtil2 = _interopRequireDefault(_servicesFormlyUtil);
  84. var _servicesFormlyWarn = __webpack_require__(12);
  85. var _servicesFormlyWarn2 = _interopRequireDefault(_servicesFormlyWarn);
  86. var _directivesFormlyCustomValidation = __webpack_require__(13);
  87. var _directivesFormlyCustomValidation2 = _interopRequireDefault(_directivesFormlyCustomValidation);
  88. var _directivesFormlyField = __webpack_require__(14);
  89. var _directivesFormlyField2 = _interopRequireDefault(_directivesFormlyField);
  90. var _directivesFormlyFocus = __webpack_require__(15);
  91. var _directivesFormlyFocus2 = _interopRequireDefault(_directivesFormlyFocus);
  92. var _directivesFormlyForm = __webpack_require__(16);
  93. var _directivesFormlyForm2 = _interopRequireDefault(_directivesFormlyForm);
  94. var _directivesFormlyFormController = __webpack_require__(17);
  95. var _directivesFormlyFormController2 = _interopRequireDefault(_directivesFormlyFormController);
  96. var _runFormlyNgModelAttrsManipulator = __webpack_require__(18);
  97. var _runFormlyNgModelAttrsManipulator2 = _interopRequireDefault(_runFormlyNgModelAttrsManipulator);
  98. var _runFormlyCustomTags = __webpack_require__(19);
  99. var _runFormlyCustomTags2 = _interopRequireDefault(_runFormlyCustomTags);
  100. var ngModuleName = 'formly';
  101. exports['default'] = ngModuleName;
  102. var ngModule = _angularFix2['default'].module(ngModuleName, []);
  103. ngModule.constant('formlyApiCheck', _providersFormlyApiCheck2['default']);
  104. ngModule.constant('formlyErrorAndWarningsUrlPrefix', _otherDocsBaseUrl2['default']);
  105. ngModule.constant('formlyVersion', ("0.0.0-semantically-released.0")); // <-- webpack variable
  106. ngModule.provider('formlyUsability', _providersFormlyUsability2['default']);
  107. ngModule.provider('formlyConfig', _providersFormlyConfig2['default']);
  108. ngModule.factory('formlyValidationMessages', _providersFormlyValidationMessages2['default']);
  109. ngModule.factory('formlyUtil', _servicesFormlyUtil2['default']);
  110. ngModule.factory('formlyWarn', _servicesFormlyWarn2['default']);
  111. ngModule.directive('formlyCustomValidation', _directivesFormlyCustomValidation2['default']);
  112. ngModule.directive('formlyField', _directivesFormlyField2['default']);
  113. ngModule.directive('formlyFocus', _directivesFormlyFocus2['default']);
  114. ngModule.directive('formlyForm', _directivesFormlyForm2['default']);
  115. ngModule.controller('FormlyFormController', _directivesFormlyFormController2['default']);
  116. ngModule.run(_runFormlyNgModelAttrsManipulator2['default']);
  117. ngModule.run(_runFormlyCustomTags2['default']);
  118. module.exports = exports['default'];
  119. /***/ },
  120. /* 2 */
  121. /***/ function(module, exports, __webpack_require__) {
  122. // some versions of angular don't export the angular module properly,
  123. // so we get it from window in this case.
  124. 'use strict';
  125. Object.defineProperty(exports, '__esModule', {
  126. value: true
  127. });
  128. var angular = __webpack_require__(3);
  129. /* istanbul ignore next */
  130. if (!angular.version) {
  131. angular = window.angular;
  132. }
  133. exports['default'] = angular;
  134. module.exports = exports['default'];
  135. /***/ },
  136. /* 3 */
  137. /***/ function(module, exports) {
  138. module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
  139. /***/ },
  140. /* 4 */
  141. /***/ function(module, exports, __webpack_require__) {
  142. 'use strict';
  143. Object.defineProperty(exports, '__esModule', {
  144. value: true
  145. });
  146. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  147. var _angularFix = __webpack_require__(2);
  148. var _angularFix2 = _interopRequireDefault(_angularFix);
  149. var _apiCheck = __webpack_require__(5);
  150. var _apiCheck2 = _interopRequireDefault(_apiCheck);
  151. var apiCheck = (0, _apiCheck2['default'])({
  152. output: {
  153. prefix: 'angular-formly:',
  154. docsBaseUrl: __webpack_require__(6)
  155. }
  156. });
  157. function shapeRequiredIfNot(otherProps, propChecker) {
  158. if (!_angularFix2['default'].isArray(otherProps)) {
  159. otherProps = [otherProps];
  160. }
  161. var type = 'specified if these are not specified: `' + otherProps.join(', ') + '` (otherwise it\'s optional)';
  162. function shapeRequiredIfNotDefinition(prop, propName, location, obj) {
  163. var propExists = obj && obj.hasOwnProperty(propName);
  164. var otherPropsExist = otherProps.some(function (otherProp) {
  165. return obj && obj.hasOwnProperty(otherProp);
  166. });
  167. if (!otherPropsExist && !propExists) {
  168. return apiCheck.utils.getError(propName, location, type);
  169. } else if (propExists) {
  170. return propChecker(prop, propName, location, obj);
  171. }
  172. }
  173. shapeRequiredIfNotDefinition.type = type;
  174. return apiCheck.utils.checkerHelpers.setupChecker(shapeRequiredIfNotDefinition);
  175. }
  176. var formlyExpression = apiCheck.oneOfType([apiCheck.string, apiCheck.func]);
  177. var specifyWrapperType = apiCheck.typeOrArrayOf(apiCheck.string).nullable;
  178. var apiCheckProperty = apiCheck.func;
  179. var apiCheckInstanceProperty = apiCheck.shape.onlyIf('apiCheck', apiCheck.func.withProperties({
  180. warn: apiCheck.func,
  181. 'throw': apiCheck.func,
  182. shape: apiCheck.func
  183. }));
  184. var apiCheckFunctionProperty = apiCheck.shape.onlyIf('apiCheck', apiCheck.oneOf(['throw', 'warn']));
  185. var formlyWrapperType = apiCheck.shape({
  186. name: shapeRequiredIfNot('types', apiCheck.string).optional,
  187. template: apiCheck.shape.ifNot('templateUrl', apiCheck.string).optional,
  188. templateUrl: apiCheck.shape.ifNot('template', apiCheck.string).optional,
  189. types: apiCheck.typeOrArrayOf(apiCheck.string).optional,
  190. overwriteOk: apiCheck.bool.optional,
  191. apiCheck: apiCheckProperty.optional,
  192. apiCheckInstance: apiCheckInstanceProperty.optional,
  193. apiCheckFunction: apiCheckFunctionProperty.optional,
  194. apiCheckOptions: apiCheck.object.optional
  195. }).strict;
  196. var expressionProperties = apiCheck.objectOf(apiCheck.oneOfType([formlyExpression, apiCheck.shape({
  197. expression: formlyExpression,
  198. message: formlyExpression.optional
  199. }).strict]));
  200. var modelChecker = apiCheck.oneOfType([apiCheck.string, apiCheck.object]);
  201. var templateManipulators = apiCheck.shape({
  202. preWrapper: apiCheck.arrayOf(apiCheck.func).nullable.optional,
  203. postWrapper: apiCheck.arrayOf(apiCheck.func).nullable.optional
  204. }).strict.nullable;
  205. var validatorChecker = apiCheck.objectOf(apiCheck.oneOfType([formlyExpression, apiCheck.shape({
  206. expression: formlyExpression,
  207. message: formlyExpression.optional
  208. }).strict]));
  209. var watcherChecker = apiCheck.typeOrArrayOf(apiCheck.shape({
  210. expression: formlyExpression.optional,
  211. listener: formlyExpression.optional,
  212. runFieldExpressions: apiCheck.bool.optional
  213. }));
  214. var fieldOptionsApiShape = {
  215. $$hashKey: apiCheck.any.optional,
  216. type: apiCheck.shape.ifNot(['template', 'templateUrl'], apiCheck.string).optional,
  217. template: apiCheck.shape.ifNot(['type', 'templateUrl'], apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional,
  218. templateUrl: apiCheck.shape.ifNot(['type', 'template'], apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional,
  219. key: apiCheck.oneOfType([apiCheck.string, apiCheck.number]).optional,
  220. model: modelChecker.optional,
  221. originalModel: modelChecker.optional,
  222. className: apiCheck.string.optional,
  223. id: apiCheck.string.optional,
  224. name: apiCheck.string.optional,
  225. expressionProperties: expressionProperties.optional,
  226. extras: apiCheck.shape({
  227. validateOnModelChange: apiCheck.bool.optional,
  228. skipNgModelAttrsManipulator: apiCheck.oneOfType([apiCheck.string, apiCheck.bool]).optional
  229. }).strict.optional,
  230. data: apiCheck.object.optional,
  231. templateOptions: apiCheck.object.optional,
  232. wrapper: specifyWrapperType.optional,
  233. modelOptions: apiCheck.shape({
  234. updateOn: apiCheck.string.optional,
  235. debounce: apiCheck.oneOfType([apiCheck.objectOf(apiCheck.number), apiCheck.number]).optional,
  236. allowInvalid: apiCheck.bool.optional,
  237. getterSetter: apiCheck.bool.optional,
  238. timezone: apiCheck.string.optional
  239. }).optional,
  240. watcher: watcherChecker.optional,
  241. validators: validatorChecker.optional,
  242. asyncValidators: validatorChecker.optional,
  243. parsers: apiCheck.arrayOf(formlyExpression).optional,
  244. formatters: apiCheck.arrayOf(formlyExpression).optional,
  245. noFormControl: apiCheck.bool.optional,
  246. hide: apiCheck.bool.optional,
  247. hideExpression: formlyExpression.optional,
  248. ngModelElAttrs: apiCheck.objectOf(apiCheck.string).optional,
  249. ngModelAttrs: apiCheck.objectOf(apiCheck.shape({
  250. statement: apiCheck.shape.ifNot(['value', 'attribute', 'bound', 'boolean'], apiCheck.any).optional,
  251. value: apiCheck.shape.ifNot('statement', apiCheck.any).optional,
  252. attribute: apiCheck.shape.ifNot('statement', apiCheck.any).optional,
  253. bound: apiCheck.shape.ifNot('statement', apiCheck.any).optional,
  254. boolean: apiCheck.shape.ifNot('statement', apiCheck.any).optional
  255. }).strict).optional,
  256. elementAttributes: apiCheck.objectOf(apiCheck.string).optional,
  257. optionsTypes: apiCheck.typeOrArrayOf(apiCheck.string).optional,
  258. link: apiCheck.func.optional,
  259. controller: apiCheck.oneOfType([apiCheck.string, apiCheck.func, apiCheck.array]).optional,
  260. validation: apiCheck.shape({
  261. show: apiCheck.bool.nullable.optional,
  262. messages: apiCheck.objectOf(formlyExpression).optional,
  263. errorExistsAndShouldBeVisible: apiCheck.bool.optional
  264. }).optional,
  265. formControl: apiCheck.typeOrArrayOf(apiCheck.object).optional,
  266. value: apiCheck.func.optional,
  267. runExpressions: apiCheck.func.optional,
  268. templateManipulators: templateManipulators.optional,
  269. resetModel: apiCheck.func.optional,
  270. updateInitialValue: apiCheck.func.optional,
  271. initialValue: apiCheck.any.optional,
  272. defaultValue: apiCheck.any.optional
  273. };
  274. var formlyFieldOptions = apiCheck.shape(fieldOptionsApiShape).strict;
  275. var formOptionsApi = apiCheck.shape({
  276. formState: apiCheck.object.optional,
  277. resetModel: apiCheck.func.optional,
  278. updateInitialValue: apiCheck.func.optional,
  279. removeChromeAutoComplete: apiCheck.bool.optional,
  280. parseKeyArrays: apiCheck.bool.optional,
  281. templateManipulators: templateManipulators.optional,
  282. manualModelWatcher: apiCheck.oneOfType([apiCheck.bool, apiCheck.func]).optional,
  283. watchAllExpressions: apiCheck.bool.optional,
  284. wrapper: specifyWrapperType.optional,
  285. fieldTransform: apiCheck.oneOfType([apiCheck.func, apiCheck.array]).optional,
  286. data: apiCheck.object.optional
  287. }).strict;
  288. var fieldGroup = apiCheck.shape({
  289. $$hashKey: apiCheck.any.optional,
  290. key: apiCheck.oneOfType([apiCheck.string, apiCheck.number]).optional,
  291. // danger. Nested field groups wont get api-checked...
  292. fieldGroup: apiCheck.arrayOf(apiCheck.oneOfType([formlyFieldOptions, apiCheck.object])),
  293. className: apiCheck.string.optional,
  294. options: formOptionsApi.optional,
  295. templateOptions: apiCheck.object.optional,
  296. wrapper: specifyWrapperType.optional,
  297. watcher: watcherChecker.optional,
  298. hide: apiCheck.bool.optional,
  299. hideExpression: formlyExpression.optional,
  300. data: apiCheck.object.optional,
  301. model: modelChecker.optional,
  302. form: apiCheck.object.optional,
  303. elementAttributes: apiCheck.objectOf(apiCheck.string).optional
  304. }).strict;
  305. var typeOptionsDefaultOptions = _angularFix2['default'].copy(fieldOptionsApiShape);
  306. typeOptionsDefaultOptions.key = apiCheck.string.optional;
  307. var formlyTypeOptions = apiCheck.shape({
  308. name: apiCheck.string,
  309. template: apiCheck.shape.ifNot('templateUrl', apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional,
  310. templateUrl: apiCheck.shape.ifNot('template', apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional,
  311. controller: apiCheck.oneOfType([apiCheck.func, apiCheck.string, apiCheck.array]).optional,
  312. link: apiCheck.func.optional,
  313. defaultOptions: apiCheck.oneOfType([apiCheck.func, apiCheck.shape(typeOptionsDefaultOptions)]).optional,
  314. 'extends': apiCheck.string.optional,
  315. wrapper: specifyWrapperType.optional,
  316. data: apiCheck.object.optional,
  317. apiCheck: apiCheckProperty.optional,
  318. apiCheckInstance: apiCheckInstanceProperty.optional,
  319. apiCheckFunction: apiCheckFunctionProperty.optional,
  320. apiCheckOptions: apiCheck.object.optional,
  321. overwriteOk: apiCheck.bool.optional
  322. }).strict;
  323. _angularFix2['default'].extend(apiCheck, {
  324. formlyTypeOptions: formlyTypeOptions, formlyFieldOptions: formlyFieldOptions, formlyExpression: formlyExpression, formlyWrapperType: formlyWrapperType, fieldGroup: fieldGroup, formOptionsApi: formOptionsApi
  325. });
  326. exports['default'] = apiCheck;
  327. module.exports = exports['default'];
  328. /***/ },
  329. /* 5 */
  330. /***/ function(module, exports) {
  331. module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
  332. /***/ },
  333. /* 6 */
  334. /***/ function(module, exports, __webpack_require__) {
  335. "use strict";
  336. Object.defineProperty(exports, "__esModule", {
  337. value: true
  338. });
  339. exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("0.0.0-semantically-released.0") + "/other/ERRORS_AND_WARNINGS.md#";
  340. module.exports = exports["default"];
  341. /***/ },
  342. /* 7 */
  343. /***/ function(module, exports, __webpack_require__) {
  344. 'use strict';
  345. formlyUsability.$inject = ["formlyApiCheck", "formlyErrorAndWarningsUrlPrefix"];
  346. Object.defineProperty(exports, '__esModule', {
  347. value: true
  348. });
  349. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  350. var _angularFix = __webpack_require__(2);
  351. var _angularFix2 = _interopRequireDefault(_angularFix);
  352. exports['default'] = formlyUsability;
  353. // @ngInject
  354. function formlyUsability(formlyApiCheck, formlyErrorAndWarningsUrlPrefix) {
  355. var _this = this;
  356. _angularFix2['default'].extend(this, {
  357. getFormlyError: getFormlyError,
  358. getFieldError: getFieldError,
  359. checkWrapper: checkWrapper,
  360. checkWrapperTemplate: checkWrapperTemplate,
  361. getErrorMessage: getErrorMessage,
  362. $get: function $get() {
  363. return _this;
  364. }
  365. });
  366. function getFieldError(errorInfoSlug, message, field) {
  367. if (arguments.length < 3) {
  368. field = message;
  369. message = errorInfoSlug;
  370. errorInfoSlug = null;
  371. }
  372. return new Error(getErrorMessage(errorInfoSlug, message) + (' Field definition: ' + _angularFix2['default'].toJson(field)));
  373. }
  374. function getFormlyError(errorInfoSlug, message) {
  375. if (!message) {
  376. message = errorInfoSlug;
  377. errorInfoSlug = null;
  378. }
  379. return new Error(getErrorMessage(errorInfoSlug, message));
  380. }
  381. function getErrorMessage(errorInfoSlug, message) {
  382. var url = '';
  383. if (errorInfoSlug !== null) {
  384. url = '' + formlyErrorAndWarningsUrlPrefix + errorInfoSlug;
  385. }
  386. return 'Formly Error: ' + message + '. ' + url;
  387. }
  388. function checkWrapper(wrapper) {
  389. formlyApiCheck['throw'](formlyApiCheck.formlyWrapperType, wrapper, {
  390. prefix: 'formlyConfig.setWrapper',
  391. urlSuffix: 'setwrapper-validation-failed'
  392. });
  393. }
  394. function checkWrapperTemplate(template, additionalInfo) {
  395. var formlyTransclude = '<formly-transclude></formly-transclude>';
  396. if (template.indexOf(formlyTransclude) === -1) {
  397. throw getFormlyError('Template wrapper templates must use "' + formlyTransclude + '" somewhere in them. ' + ('This one does not have "<formly-transclude></formly-transclude>" in it: ' + template) + '\n' + ('Additional information: ' + JSON.stringify(additionalInfo)));
  398. }
  399. }
  400. }
  401. module.exports = exports['default'];
  402. /***/ },
  403. /* 8 */
  404. /***/ function(module, exports, __webpack_require__) {
  405. 'use strict';
  406. formlyConfig.$inject = ["formlyUsabilityProvider", "formlyErrorAndWarningsUrlPrefix", "formlyApiCheck"];
  407. Object.defineProperty(exports, '__esModule', {
  408. value: true
  409. });
  410. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  411. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
  412. var _angularFix = __webpack_require__(2);
  413. var _angularFix2 = _interopRequireDefault(_angularFix);
  414. var _otherUtils = __webpack_require__(9);
  415. var _otherUtils2 = _interopRequireDefault(_otherUtils);
  416. exports['default'] = formlyConfig;
  417. // @ngInject
  418. function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix, formlyApiCheck) {
  419. var _this2 = this;
  420. var typeMap = {};
  421. var templateWrappersMap = {};
  422. var defaultWrapperName = 'default';
  423. var _this = this;
  424. var getError = formlyUsabilityProvider.getFormlyError;
  425. _angularFix2['default'].extend(this, {
  426. setType: setType,
  427. getType: getType,
  428. getTypes: getTypes,
  429. getTypeHeritage: getTypeHeritage,
  430. setWrapper: setWrapper,
  431. getWrapper: getWrapper,
  432. getWrapperByType: getWrapperByType,
  433. removeWrapperByName: removeWrapperByName,
  434. removeWrappersForType: removeWrappersForType,
  435. disableWarnings: false,
  436. extras: {
  437. disableNgModelAttrsManipulator: false,
  438. fieldTransform: [],
  439. ngModelAttrsManipulatorPreferUnbound: false,
  440. removeChromeAutoComplete: false,
  441. parseKeyArrays: false,
  442. defaultHideDirective: 'ng-if',
  443. getFieldId: null
  444. },
  445. templateManipulators: {
  446. preWrapper: [],
  447. postWrapper: []
  448. },
  449. $get: function $get() {
  450. return _this2;
  451. }
  452. });
  453. function setType(options) {
  454. if (_angularFix2['default'].isArray(options)) {
  455. var _ret = (function () {
  456. var allTypes = [];
  457. _angularFix2['default'].forEach(options, function (item) {
  458. allTypes.push(setType(item));
  459. });
  460. return {
  461. v: allTypes
  462. };
  463. })();
  464. if (typeof _ret === 'object') return _ret.v;
  465. } else if (_angularFix2['default'].isObject(options)) {
  466. checkType(options);
  467. if (options['extends']) {
  468. extendTypeOptions(options);
  469. }
  470. typeMap[options.name] = options;
  471. return typeMap[options.name];
  472. } else {
  473. throw getError('You must provide an object or array for setType. You provided: ' + JSON.stringify(arguments));
  474. }
  475. }
  476. function checkType(options) {
  477. formlyApiCheck['throw'](formlyApiCheck.formlyTypeOptions, options, {
  478. prefix: 'formlyConfig.setType',
  479. url: 'settype-validation-failed'
  480. });
  481. if (!options.overwriteOk) {
  482. checkOverwrite(options.name, typeMap, options, 'types');
  483. } else {
  484. options.overwriteOk = undefined;
  485. }
  486. }
  487. function extendTypeOptions(options) {
  488. var extendsType = getType(options['extends'], true, options);
  489. extendTypeControllerFunction(options, extendsType);
  490. extendTypeLinkFunction(options, extendsType);
  491. extendTypeDefaultOptions(options, extendsType);
  492. _otherUtils2['default'].reverseDeepMerge(options, extendsType);
  493. extendTemplate(options, extendsType);
  494. }
  495. function extendTemplate(options, extendsType) {
  496. if (options.template && extendsType.templateUrl) {
  497. delete options.templateUrl;
  498. } else if (options.templateUrl && extendsType.template) {
  499. delete options.template;
  500. }
  501. }
  502. function extendTypeControllerFunction(options, extendsType) {
  503. var extendsCtrl = extendsType.controller;
  504. if (!_angularFix2['default'].isDefined(extendsCtrl)) {
  505. return;
  506. }
  507. var optionsCtrl = options.controller;
  508. if (_angularFix2['default'].isDefined(optionsCtrl)) {
  509. options.controller = function ($scope, $controller) {
  510. $controller(extendsCtrl, { $scope: $scope });
  511. $controller(optionsCtrl, { $scope: $scope });
  512. };
  513. options.controller.$inject = ['$scope', '$controller'];
  514. } else {
  515. options.controller = extendsCtrl;
  516. }
  517. }
  518. function extendTypeLinkFunction(options, extendsType) {
  519. var extendsFn = extendsType.link;
  520. if (!_angularFix2['default'].isDefined(extendsFn)) {
  521. return;
  522. }
  523. var optionsFn = options.link;
  524. if (_angularFix2['default'].isDefined(optionsFn)) {
  525. options.link = function () {
  526. extendsFn.apply(undefined, arguments);
  527. optionsFn.apply(undefined, arguments);
  528. };
  529. } else {
  530. options.link = extendsFn;
  531. }
  532. }
  533. function extendTypeDefaultOptions(options, extendsType) {
  534. var extendsDO = extendsType.defaultOptions;
  535. if (!_angularFix2['default'].isDefined(extendsDO)) {
  536. return;
  537. }
  538. var optionsDO = options.defaultOptions || {};
  539. var optionsDOIsFn = _angularFix2['default'].isFunction(optionsDO);
  540. var extendsDOIsFn = _angularFix2['default'].isFunction(extendsDO);
  541. if (extendsDOIsFn) {
  542. options.defaultOptions = function defaultOptions(opts, scope) {
  543. var extendsDefaultOptions = extendsDO(opts, scope);
  544. var mergedDefaultOptions = {};
  545. _otherUtils2['default'].reverseDeepMerge(mergedDefaultOptions, opts, extendsDefaultOptions);
  546. var extenderOptionsDefaultOptions = optionsDO;
  547. if (optionsDOIsFn) {
  548. extenderOptionsDefaultOptions = extenderOptionsDefaultOptions(mergedDefaultOptions, scope);
  549. }
  550. _otherUtils2['default'].reverseDeepMerge(extenderOptionsDefaultOptions, extendsDefaultOptions);
  551. return extenderOptionsDefaultOptions;
  552. };
  553. } else if (optionsDOIsFn) {
  554. options.defaultOptions = function defaultOptions(opts, scope) {
  555. var newDefaultOptions = {};
  556. _otherUtils2['default'].reverseDeepMerge(newDefaultOptions, opts, extendsDO);
  557. return optionsDO(newDefaultOptions, scope);
  558. };
  559. }
  560. }
  561. function getType(name, throwError, errorContext) {
  562. if (!name) {
  563. return undefined;
  564. }
  565. var type = typeMap[name];
  566. if (!type && throwError === true) {
  567. throw getError('There is no type by the name of "' + name + '": ' + JSON.stringify(errorContext));
  568. } else {
  569. return type;
  570. }
  571. }
  572. function getTypes() {
  573. return typeMap;
  574. }
  575. function getTypeHeritage(parent) {
  576. var heritage = [];
  577. var type = parent;
  578. if (_angularFix2['default'].isString(type)) {
  579. type = getType(parent);
  580. }
  581. parent = type['extends'];
  582. while (parent) {
  583. type = getType(parent);
  584. heritage.push(type);
  585. parent = type['extends'];
  586. }
  587. return heritage;
  588. }
  589. function setWrapper(_x, _x2) {
  590. var _again = true;
  591. _function: while (_again) {
  592. var options = _x,
  593. name = _x2;
  594. _again = false;
  595. if (_angularFix2['default'].isArray(options)) {
  596. return options.map(function (wrapperOptions) {
  597. return setWrapper(wrapperOptions);
  598. });
  599. } else if (_angularFix2['default'].isObject(options)) {
  600. options.types = getOptionsTypes(options);
  601. options.name = getOptionsName(options, name);
  602. checkWrapperAPI(options);
  603. templateWrappersMap[options.name] = options;
  604. return options;
  605. } else if (_angularFix2['default'].isString(options)) {
  606. _x = {
  607. template: options,
  608. name: name
  609. };
  610. _x2 = undefined;
  611. _again = true;
  612. continue _function;
  613. }
  614. }
  615. }
  616. function getOptionsTypes(options) {
  617. if (_angularFix2['default'].isString(options.types)) {
  618. return [options.types];
  619. }
  620. if (!_angularFix2['default'].isDefined(options.types)) {
  621. return [];
  622. } else {
  623. return options.types;
  624. }
  625. }
  626. function getOptionsName(options, name) {
  627. return options.name || name || options.types.join(' ') || defaultWrapperName;
  628. }
  629. function checkWrapperAPI(options) {
  630. formlyUsabilityProvider.checkWrapper(options);
  631. if (options.template) {
  632. formlyUsabilityProvider.checkWrapperTemplate(options.template, options);
  633. }
  634. if (!options.overwriteOk) {
  635. checkOverwrite(options.name, templateWrappersMap, options, 'templateWrappers');
  636. } else {
  637. delete options.overwriteOk;
  638. }
  639. checkWrapperTypes(options);
  640. }
  641. function checkWrapperTypes(options) {
  642. var shouldThrow = !_angularFix2['default'].isArray(options.types) || !options.types.every(_angularFix2['default'].isString);
  643. if (shouldThrow) {
  644. throw getError('Attempted to create a template wrapper with types that is not a string or an array of strings');
  645. }
  646. }
  647. function checkOverwrite(property, object, newValue, objectName) {
  648. if (object.hasOwnProperty(property)) {
  649. warn('overwriting-types-or-wrappers', ['Attempting to overwrite ' + property + ' on ' + objectName + ' which is currently', JSON.stringify(object[property]) + ' with ' + JSON.stringify(newValue), 'To supress this warning, specify the property "overwriteOk: true"'].join(' '));
  650. }
  651. }
  652. function getWrapper(name) {
  653. return templateWrappersMap[name || defaultWrapperName];
  654. }
  655. function getWrapperByType(type) {
  656. /* eslint prefer-const:0 */
  657. var wrappers = [];
  658. for (var _name in templateWrappersMap) {
  659. if (templateWrappersMap.hasOwnProperty(_name)) {
  660. if (templateWrappersMap[_name].types && templateWrappersMap[_name].types.indexOf(type) !== -1) {
  661. wrappers.push(templateWrappersMap[_name]);
  662. }
  663. }
  664. }
  665. return wrappers;
  666. }
  667. function removeWrapperByName(name) {
  668. var wrapper = templateWrappersMap[name];
  669. delete templateWrappersMap[name];
  670. return wrapper;
  671. }
  672. function removeWrappersForType(type) {
  673. var wrappers = getWrapperByType(type);
  674. if (!wrappers) {
  675. return undefined;
  676. }
  677. if (!_angularFix2['default'].isArray(wrappers)) {
  678. return removeWrapperByName(wrappers.name);
  679. } else {
  680. wrappers.forEach(function (wrapper) {
  681. return removeWrapperByName(wrapper.name);
  682. });
  683. return wrappers;
  684. }
  685. }
  686. function warn() {
  687. if (!_this.disableWarnings && console.warn) {
  688. /* eslint no-console:0 */
  689. var args = Array.prototype.slice.call(arguments);
  690. var warnInfoSlug = args.shift();
  691. args.unshift('Formly Warning:');
  692. args.push('' + formlyErrorAndWarningsUrlPrefix + warnInfoSlug);
  693. console.warn.apply(console, _toConsumableArray(args));
  694. }
  695. }
  696. }
  697. module.exports = exports['default'];
  698. /***/ },
  699. /* 9 */
  700. /***/ function(module, exports, __webpack_require__) {
  701. 'use strict';
  702. Object.defineProperty(exports, '__esModule', {
  703. value: true
  704. });
  705. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  706. var _angularFix = __webpack_require__(2);
  707. var _angularFix2 = _interopRequireDefault(_angularFix);
  708. exports['default'] = {
  709. containsSelector: containsSelector, containsSpecialChar: containsSpecialChar, formlyEval: formlyEval, getFieldId: getFieldId, reverseDeepMerge: reverseDeepMerge, findByNodeName: findByNodeName,
  710. arrayify: arrayify, extendFunction: extendFunction, extendArray: extendArray, startsWith: startsWith, contains: contains
  711. };
  712. function containsSelector(string) {
  713. return containsSpecialChar(string, '.') || containsSpecialChar(string, '[') && containsSpecialChar(string, ']');
  714. }
  715. function containsSpecialChar(a, b) {
  716. if (!a || !a.indexOf) {
  717. return false;
  718. }
  719. return a.indexOf(b) !== -1;
  720. }
  721. function formlyEval(scope, expression, $modelValue, $viewValue, extraLocals) {
  722. if (_angularFix2['default'].isFunction(expression)) {
  723. return expression($viewValue, $modelValue, scope, extraLocals);
  724. } else {
  725. return scope.$eval(expression, _angularFix2['default'].extend({ $viewValue: $viewValue, $modelValue: $modelValue }, extraLocals));
  726. }
  727. }
  728. function getFieldId(formId, options, index) {
  729. if (options.id) {
  730. return options.id;
  731. }
  732. var type = options.type;
  733. if (!type && options.template) {
  734. type = 'template';
  735. } else if (!type && options.templateUrl) {
  736. type = 'templateUrl';
  737. }
  738. return [formId, type, options.key, index].join('_');
  739. }
  740. function reverseDeepMerge(dest) {
  741. _angularFix2['default'].forEach(arguments, function (src, index) {
  742. if (!index) {
  743. return;
  744. }
  745. _angularFix2['default'].forEach(src, function (val, prop) {
  746. if (!_angularFix2['default'].isDefined(dest[prop])) {
  747. dest[prop] = _angularFix2['default'].copy(val);
  748. } else if (objAndSameType(dest[prop], val)) {
  749. reverseDeepMerge(dest[prop], val);
  750. }
  751. });
  752. });
  753. return dest;
  754. }
  755. function objAndSameType(obj1, obj2) {
  756. return _angularFix2['default'].isObject(obj1) && _angularFix2['default'].isObject(obj2) && Object.getPrototypeOf(obj1) === Object.getPrototypeOf(obj2);
  757. }
  758. // recurse down a node tree to find a node with matching nodeName, for custom tags jQuery.find doesn't work in IE8
  759. function findByNodeName(el, nodeName) {
  760. if (!el.prop) {
  761. // not a jQuery or jqLite object -> wrap it
  762. el = _angularFix2['default'].element(el);
  763. }
  764. if (el.prop('nodeName') === nodeName.toUpperCase()) {
  765. return el;
  766. }
  767. var c = el.children();
  768. for (var i = 0; c && i < c.length; i++) {
  769. var node = findByNodeName(c[i], nodeName);
  770. if (node) {
  771. return node;
  772. }
  773. }
  774. }
  775. function arrayify(obj) {
  776. if (obj && !_angularFix2['default'].isArray(obj)) {
  777. obj = [obj];
  778. } else if (!obj) {
  779. obj = [];
  780. }
  781. return obj;
  782. }
  783. function extendFunction() {
  784. for (var _len = arguments.length, fns = Array(_len), _key = 0; _key < _len; _key++) {
  785. fns[_key] = arguments[_key];
  786. }
  787. return function extendedFunction() {
  788. var args = arguments;
  789. fns.forEach(function (fn) {
  790. return fn.apply(null, args);
  791. });
  792. };
  793. }
  794. function extendArray(primary, secondary, property) {
  795. if (property) {
  796. primary = primary[property];
  797. secondary = secondary[property];
  798. }
  799. if (secondary && primary) {
  800. _angularFix2['default'].forEach(secondary, function (item) {
  801. if (primary.indexOf(item) === -1) {
  802. primary.push(item);
  803. }
  804. });
  805. return primary;
  806. } else if (secondary) {
  807. return secondary;
  808. } else {
  809. return primary;
  810. }
  811. }
  812. function startsWith(str, search) {
  813. if (_angularFix2['default'].isString(str) && _angularFix2['default'].isString(search)) {
  814. return str.length >= search.length && str.substring(0, search.length) === search;
  815. } else {
  816. return false;
  817. }
  818. }
  819. function contains(str, search) {
  820. if (_angularFix2['default'].isString(str) && _angularFix2['default'].isString(search)) {
  821. return str.length >= search.length && str.indexOf(search) !== -1;
  822. } else {
  823. return false;
  824. }
  825. }
  826. module.exports = exports['default'];
  827. /***/ },
  828. /* 10 */
  829. /***/ function(module, exports) {
  830. 'use strict';
  831. Object.defineProperty(exports, '__esModule', {
  832. value: true
  833. });
  834. exports['default'] = formlyValidationMessages;
  835. // @ngInject
  836. function formlyValidationMessages() {
  837. var validationMessages = {
  838. addTemplateOptionValueMessage: addTemplateOptionValueMessage,
  839. addStringMessage: addStringMessage,
  840. messages: {}
  841. };
  842. return validationMessages;
  843. function addTemplateOptionValueMessage(name, prop, prefix, suffix, alternate) {
  844. validationMessages.messages[name] = templateOptionValue(prop, prefix, suffix, alternate);
  845. }
  846. function addStringMessage(name, string) {
  847. validationMessages.messages[name] = function () {
  848. return string;
  849. };
  850. }
  851. function templateOptionValue(prop, prefix, suffix, alternate) {
  852. return function getValidationMessage(viewValue, modelValue, scope) {
  853. if (typeof scope.options.templateOptions[prop] !== 'undefined') {
  854. return prefix + ' ' + scope.options.templateOptions[prop] + ' ' + suffix;
  855. } else {
  856. return alternate;
  857. }
  858. };
  859. }
  860. }
  861. module.exports = exports['default'];
  862. /***/ },
  863. /* 11 */
  864. /***/ function(module, exports, __webpack_require__) {
  865. 'use strict';
  866. Object.defineProperty(exports, '__esModule', {
  867. value: true
  868. });
  869. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  870. var _otherUtils = __webpack_require__(9);
  871. var _otherUtils2 = _interopRequireDefault(_otherUtils);
  872. exports['default'] = formlyUtil;
  873. // @ngInject
  874. function formlyUtil() {
  875. return _otherUtils2['default'];
  876. }
  877. module.exports = exports['default'];
  878. /***/ },
  879. /* 12 */
  880. /***/ function(module, exports) {
  881. 'use strict';
  882. formlyWarn.$inject = ["formlyConfig", "formlyErrorAndWarningsUrlPrefix", "$log"];
  883. Object.defineProperty(exports, '__esModule', {
  884. value: true
  885. });
  886. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
  887. exports['default'] = formlyWarn;
  888. // @ngInject
  889. function formlyWarn(formlyConfig, formlyErrorAndWarningsUrlPrefix, $log) {
  890. return function warn() {
  891. if (!formlyConfig.disableWarnings) {
  892. var args = Array.prototype.slice.call(arguments);
  893. var warnInfoSlug = args.shift();
  894. args.unshift('Formly Warning:');
  895. args.push('' + formlyErrorAndWarningsUrlPrefix + warnInfoSlug);
  896. $log.warn.apply($log, _toConsumableArray(args));
  897. }
  898. };
  899. }
  900. module.exports = exports['default'];
  901. /***/ },
  902. /* 13 */
  903. /***/ function(module, exports, __webpack_require__) {
  904. 'use strict';
  905. formlyCustomValidation.$inject = ["formlyUtil"];
  906. Object.defineProperty(exports, '__esModule', {
  907. value: true
  908. });
  909. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  910. var _angularFix = __webpack_require__(2);
  911. var _angularFix2 = _interopRequireDefault(_angularFix);
  912. exports['default'] = formlyCustomValidation;
  913. // @ngInject
  914. function formlyCustomValidation(formlyUtil) {
  915. return {
  916. restrict: 'A',
  917. require: 'ngModel',
  918. link: function formlyCustomValidationLink(scope, el, attrs, ctrl) {
  919. var opts = scope.options;
  920. opts.validation.messages = opts.validation.messages || {};
  921. _angularFix2['default'].forEach(opts.validation.messages, function (message, key) {
  922. opts.validation.messages[key] = function () {
  923. return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue);
  924. };
  925. });
  926. var useNewValidatorsApi = ctrl.hasOwnProperty('$validators') && !attrs.hasOwnProperty('useParsers');
  927. _angularFix2['default'].forEach(opts.validators, _angularFix2['default'].bind(null, addValidatorToPipeline, false));
  928. _angularFix2['default'].forEach(opts.asyncValidators, _angularFix2['default'].bind(null, addValidatorToPipeline, true));
  929. function addValidatorToPipeline(isAsync, validator, name) {
  930. setupMessage(validator, name);
  931. validator = _angularFix2['default'].isObject(validator) ? validator.expression : validator;
  932. if (useNewValidatorsApi) {
  933. setupWithValidators(validator, name, isAsync);
  934. } else {
  935. setupWithParsers(validator, name, isAsync);
  936. }
  937. }
  938. function setupMessage(validator, name) {
  939. var message = validator.message;
  940. if (message) {
  941. opts.validation.messages[name] = function () {
  942. return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue);
  943. };
  944. }
  945. }
  946. function setupWithValidators(validator, name, isAsync) {
  947. var validatorCollection = isAsync ? '$asyncValidators' : '$validators';
  948. ctrl[validatorCollection][name] = function evalValidity(modelValue, viewValue) {
  949. return formlyUtil.formlyEval(scope, validator, modelValue, viewValue);
  950. };
  951. }
  952. function setupWithParsers(validator, name, isAsync) {
  953. var inFlightValidator = undefined;
  954. ctrl.$parsers.unshift(function evalValidityOfParser(viewValue) {
  955. var isValid = formlyUtil.formlyEval(scope, validator, ctrl.$modelValue, viewValue);
  956. if (isAsync) {
  957. ctrl.$pending = ctrl.$pending || {};
  958. ctrl.$pending[name] = true;
  959. inFlightValidator = isValid;
  960. isValid.then(function () {
  961. if (inFlightValidator === isValid) {
  962. ctrl.$setValidity(name, true);
  963. }
  964. })['catch'](function () {
  965. if (inFlightValidator === isValid) {
  966. ctrl.$setValidity(name, false);
  967. }
  968. })['finally'](function () {
  969. var $pending = ctrl.$pending || {};
  970. if (Object.keys($pending).length === 1) {
  971. delete ctrl.$pending;
  972. } else {
  973. delete ctrl.$pending[name];
  974. }
  975. });
  976. } else {
  977. ctrl.$setValidity(name, isValid);
  978. }
  979. return viewValue;
  980. });
  981. }
  982. }
  983. };
  984. }
  985. module.exports = exports['default'];
  986. /***/ },
  987. /* 14 */
  988. /***/ function(module, exports, __webpack_require__) {
  989. 'use strict';
  990. formlyField.$inject = ["$http", "$q", "$compile", "$templateCache", "$interpolate", "formlyConfig", "formlyApiCheck", "formlyUtil", "formlyUsability", "formlyWarn"];
  991. Object.defineProperty(exports, '__esModule', {
  992. value: true
  993. });
  994. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  995. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
  996. var _angularFix = __webpack_require__(2);
  997. var _angularFix2 = _interopRequireDefault(_angularFix);
  998. var _apiCheck = __webpack_require__(5);
  999. var _apiCheck2 = _interopRequireDefault(_apiCheck);
  1000. exports['default'] = formlyField;
  1001. /**
  1002. * @ngdoc directive
  1003. * @name formlyField
  1004. * @restrict AE
  1005. */
  1006. // @ngInject
  1007. function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyConfig, formlyApiCheck, formlyUtil, formlyUsability, formlyWarn) {
  1008. FormlyFieldController.$inject = ["$scope", "$timeout", "$parse", "$controller", "formlyValidationMessages"];
  1009. var arrayify = formlyUtil.arrayify;
  1010. return {
  1011. restrict: 'AE',
  1012. transclude: true,
  1013. require: '?^formlyForm',
  1014. scope: {
  1015. options: '=',
  1016. model: '=',
  1017. originalModel: '=?',
  1018. formId: '@', // TODO remove formId in a breaking release
  1019. index: '=?',
  1020. fields: '=?',
  1021. formState: '=?',
  1022. formOptions: '=?',
  1023. form: '=?' },
  1024. // TODO require form in a breaking release
  1025. controller: FormlyFieldController,
  1026. link: fieldLink
  1027. };
  1028. // @ngInject
  1029. function FormlyFieldController($scope, $timeout, $parse, $controller, formlyValidationMessages) {
  1030. /* eslint max-statements:[2, 37] */
  1031. if ($scope.options.fieldGroup) {
  1032. setupFieldGroup();
  1033. return;
  1034. }
  1035. var fieldType = getFieldType($scope.options);
  1036. simplifyLife($scope.options);
  1037. mergeFieldOptionsWithTypeDefaults($scope.options, fieldType);
  1038. extendOptionsWithDefaults($scope.options, $scope.index);
  1039. checkApi($scope.options);
  1040. // set field id to link labels and fields
  1041. // initalization
  1042. setFieldIdAndName();
  1043. setDefaultValue();
  1044. setInitialValue();
  1045. runExpressions();
  1046. watchExpressions();
  1047. addValidationMessages($scope.options);
  1048. invokeControllers($scope, $scope.options, fieldType);
  1049. // function definitions
  1050. function runExpressions() {
  1051. var deferred = $q.defer();
  1052. // must run on next tick to make sure that the current value is correct.
  1053. $timeout(function runExpressionsOnNextTick() {
  1054. var promises = [];
  1055. var field = $scope.options;
  1056. var currentValue = valueGetterSetter();
  1057. _angularFix2['default'].forEach(field.expressionProperties, function runExpression(expression, prop) {
  1058. var setter = $parse(prop).assign;
  1059. var promise = $q.when(formlyUtil.formlyEval($scope, expression, currentValue, currentValue)).then(function setFieldValue(value) {
  1060. setter(field, value);
  1061. });
  1062. promises.push(promise);
  1063. });
  1064. $q.all(promises).then(function () {
  1065. deferred.resolve();
  1066. });
  1067. }, 0, false);
  1068. return deferred.promise;
  1069. }
  1070. function watchExpressions() {
  1071. if ($scope.formOptions.watchAllExpressions) {
  1072. (function () {
  1073. var field = $scope.options;
  1074. var currentValue = valueGetterSetter();
  1075. _angularFix2['default'].forEach(field.expressionProperties, function watchExpression(expression, prop) {
  1076. var setter = $parse(prop).assign;
  1077. $scope.$watch(function expressionPropertyWatcher() {
  1078. return formlyUtil.formlyEval($scope, expression, currentValue, currentValue);
  1079. }, function expressionPropertyListener(value) {
  1080. setter(field, value);
  1081. }, true);
  1082. });
  1083. })();
  1084. }
  1085. }
  1086. function valueGetterSetter(newVal) {
  1087. if (!$scope.model || !$scope.options.key) {
  1088. return undefined;
  1089. }
  1090. if (_angularFix2['default'].isDefined(newVal)) {
  1091. parseSet($scope.options.key, $scope.model, newVal);
  1092. }
  1093. return parseGet($scope.options.key, $scope.model);
  1094. }
  1095. function shouldNotUseParseKey(key) {
  1096. return _angularFix2['default'].isNumber(key) || !formlyUtil.containsSelector(key);
  1097. }
  1098. function keyContainsArrays(key) {
  1099. return (/\[\d{1,}\]/.test(key)
  1100. );
  1101. }
  1102. function deepAssign(obj, prop, value) {
  1103. if (_angularFix2['default'].isString(prop)) {
  1104. prop = prop.replace(/\[(\w+)\]/g, '.$1').split('.');
  1105. }
  1106. if (prop.length > 1) {
  1107. var e = prop.shift();
  1108. obj[e] = obj[e] || isNaN(prop[0]) ? {} : [];
  1109. deepAssign(obj[e], prop, value);
  1110. } else {
  1111. obj[prop[0]] = value;
  1112. }
  1113. }
  1114. function parseSet(key, model, newVal) {
  1115. // If either of these are null/undefined then just return undefined
  1116. if (!key && key !== 0 || !model) {
  1117. return;
  1118. }
  1119. // If we are working with a number then $parse wont work, default back to the old way for now
  1120. if (shouldNotUseParseKey(key)) {
  1121. // TODO: Fix this so we can get several levels instead of just one with properties that are numeric
  1122. model[key] = newVal;
  1123. } else if (formlyConfig.extras.parseKeyArrays && keyContainsArrays(key)) {
  1124. deepAssign($scope.model, key, newVal);
  1125. } else {
  1126. var setter = $parse($scope.options.key).assign;
  1127. if (setter) {
  1128. setter($scope.model, newVal);
  1129. }
  1130. }
  1131. }
  1132. function parseGet(key, model) {
  1133. // If either of these are null/undefined then just return undefined
  1134. if (!key && key !== 0 || !model) {
  1135. return undefined;
  1136. }
  1137. // If we are working with a number then $parse wont work, default back to the old way for now
  1138. if (shouldNotUseParseKey(key)) {
  1139. // TODO: Fix this so we can get several levels instead of just one with properties that are numeric
  1140. return model[key];
  1141. } else {
  1142. return $parse(key)(model);
  1143. }
  1144. }
  1145. function simplifyLife(options) {
  1146. // add a few empty objects (if they don't already exist) so you don't have to undefined check everywhere
  1147. formlyUtil.reverseDeepMerge(options, {
  1148. originalModel: options.model,
  1149. extras: {},
  1150. data: {},
  1151. templateOptions: {},
  1152. validation: {}
  1153. });
  1154. // create $scope.to so template authors can reference to instead of $scope.options.templateOptions
  1155. $scope.to = $scope.options.templateOptions;
  1156. $scope.formOptions = $scope.formOptions || {};
  1157. }
  1158. function setFieldIdAndName() {
  1159. if (_angularFix2['default'].isFunction(formlyConfig.extras.getFieldId)) {
  1160. $scope.id = formlyConfig.extras.getFieldId($scope.options, $scope.model, $scope);
  1161. } else {
  1162. var formName = $scope.form && $scope.form.$name || $scope.formId;
  1163. $scope.id = formlyUtil.getFieldId(formName, $scope.options, $scope.index);
  1164. }
  1165. $scope.options.id = $scope.id;
  1166. $scope.name = $scope.options.name || $scope.options.id;
  1167. $scope.options.name = $scope.name;
  1168. }
  1169. function setDefaultValue() {
  1170. if (_angularFix2['default'].isDefined($scope.options.defaultValue) && !_angularFix2['default'].isDefined(parseGet($scope.options.key, $scope.model))) {
  1171. parseSet($scope.options.key, $scope.model, $scope.options.defaultValue);
  1172. }
  1173. }
  1174. function setInitialValue() {
  1175. $scope.options.initialValue = $scope.model && parseGet($scope.options.key, $scope.model);
  1176. }
  1177. function mergeFieldOptionsWithTypeDefaults(options, type) {
  1178. if (type) {
  1179. mergeOptions(options, type.defaultOptions);
  1180. }
  1181. var properOrder = arrayify(options.optionsTypes).reverse(); // so the right things are overridden
  1182. _angularFix2['default'].forEach(properOrder, function (typeName) {
  1183. mergeOptions(options, formlyConfig.getType(typeName, true, options).defaultOptions);
  1184. });
  1185. }
  1186. function mergeOptions(options, extraOptions) {
  1187. if (extraOptions) {
  1188. if (_angularFix2['default'].isFunction(extraOptions)) {
  1189. extraOptions = extraOptions(options, $scope);
  1190. }
  1191. formlyUtil.reverseDeepMerge(options, extraOptions);
  1192. }
  1193. }
  1194. function extendOptionsWithDefaults(options, index) {
  1195. var key = options.key || index || 0;
  1196. _angularFix2['default'].extend(options, {
  1197. // attach the key in case the formly-field directive is used directly
  1198. key: key,
  1199. value: options.value || valueGetterSetter,
  1200. runExpressions: runExpressions,
  1201. resetModel: resetModel,
  1202. updateInitialValue: updateInitialValue
  1203. });
  1204. }
  1205. function resetModel() {
  1206. parseSet($scope.options.key, $scope.model, $scope.options.initialValue);
  1207. if ($scope.options.formControl) {
  1208. if (_angularFix2['default'].isArray($scope.options.formControl)) {
  1209. _angularFix2['default'].forEach($scope.options.formControl, function (formControl) {
  1210. resetFormControl(formControl, true);
  1211. });
  1212. } else {
  1213. resetFormControl($scope.options.formControl);
  1214. }
  1215. }
  1216. if ($scope.form) {
  1217. $scope.form.$setUntouched && $scope.form.$setUntouched();
  1218. $scope.form.$setPristine();
  1219. }
  1220. }
  1221. function resetFormControl(formControl, isMultiNgModel) {
  1222. if (!isMultiNgModel) {
  1223. formControl.$setViewValue(parseGet($scope.options.key, $scope.model));
  1224. }
  1225. formControl.$render();
  1226. formControl.$setUntouched && formControl.$setUntouched();
  1227. formControl.$setPristine();
  1228. // To prevent breaking change requiring a digest to reset $viewModel
  1229. if (!$scope.$root.$$phase) {
  1230. $scope.$digest();
  1231. }
  1232. }
  1233. function updateInitialValue() {
  1234. $scope.options.initialValue = parseGet($scope.options.key, $scope.model);
  1235. }
  1236. function addValidationMessages(options) {
  1237. options.validation.messages = options.validation.messages || {};
  1238. _angularFix2['default'].forEach(formlyValidationMessages.messages, function createFunctionForMessage(expression, name) {
  1239. if (!options.validation.messages[name]) {
  1240. options.validation.messages[name] = function evaluateMessage(viewValue, modelValue, scope) {
  1241. return formlyUtil.formlyEval(scope, expression, modelValue, viewValue);
  1242. };
  1243. }
  1244. });
  1245. }
  1246. function invokeControllers(scope) {
  1247. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  1248. var type = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  1249. _angularFix2['default'].forEach([type.controller, options.controller], function (controller) {
  1250. if (controller) {
  1251. $controller(controller, { $scope: scope });
  1252. }
  1253. });
  1254. }
  1255. function setupFieldGroup() {
  1256. $scope.options.options = $scope.options.options || {};
  1257. $scope.options.options.formState = $scope.formState;
  1258. $scope.to = $scope.options.templateOptions;
  1259. }
  1260. }
  1261. // link function
  1262. function fieldLink(scope, el, attrs, formlyFormCtrl) {
  1263. if (scope.options.fieldGroup) {
  1264. setFieldGroupTemplate();
  1265. return;
  1266. }
  1267. // watch the field model (if exists) if there is no parent formly-form directive (that would watch it instead)
  1268. if (!formlyFormCtrl && scope.options.model) {
  1269. scope.$watch('options.model', function () {
  1270. return scope.options.runExpressions();
  1271. }, true);
  1272. }
  1273. addAttributes();
  1274. addClasses();
  1275. var type = getFieldType(scope.options);
  1276. var args = arguments;
  1277. var thusly = this;
  1278. var fieldCount = 0;
  1279. var fieldManipulators = getManipulators(scope.options, scope.formOptions);
  1280. getFieldTemplate(scope.options).then(runManipulators(fieldManipulators.preWrapper)).then(transcludeInWrappers(scope.options, scope.formOptions)).then(runManipulators(fieldManipulators.postWrapper)).then(setElementTemplate).then(watchFormControl).then(callLinkFunctions)['catch'](function (error) {
  1281. formlyWarn('there-was-a-problem-setting-the-template-for-this-field', 'There was a problem setting the template for this field ', scope.options, error);
  1282. });
  1283. function setFieldGroupTemplate() {
  1284. checkFieldGroupApi(scope.options);
  1285. el.addClass('formly-field-group');
  1286. var extraAttributes = '';
  1287. if (scope.options.elementAttributes) {
  1288. extraAttributes = Object.keys(scope.options.elementAttributes).map(function (key) {
  1289. return key + '="' + scope.options.elementAttributes[key] + '"';
  1290. }).join(' ');
  1291. }
  1292. var modelValue = 'model';
  1293. scope.options.form = scope.form;
  1294. if (scope.options.key) {
  1295. modelValue = 'model[\'' + scope.options.key + '\']';
  1296. }
  1297. getTemplate('\n <formly-form model="' + modelValue + '"\n fields="options.fieldGroup"\n options="options.options"\n form="options.form"\n class="' + scope.options.className + '"\n ' + extraAttributes + '\n is-field-group>\n </formly-form>\n ').then(transcludeInWrappers(scope.options, scope.formOptions)).then(setElementTemplate);
  1298. }
  1299. function addAttributes() {
  1300. if (scope.options.elementAttributes) {
  1301. el.attr(scope.options.elementAttributes);
  1302. }
  1303. }
  1304. function addClasses() {
  1305. if (scope.options.className) {
  1306. el.addClass(scope.options.className);
  1307. }
  1308. if (scope.options.type) {
  1309. el.addClass('formly-field-' + scope.options.type);
  1310. }
  1311. }
  1312. function setElementTemplate(templateString) {
  1313. el.html(asHtml(templateString));
  1314. $compile(el.contents())(scope);
  1315. return templateString;
  1316. }
  1317. function watchFormControl(templateString) {
  1318. var stopWatchingShowError = _angularFix2['default'].noop;
  1319. if (scope.options.noFormControl) {
  1320. return;
  1321. }
  1322. var templateEl = _angularFix2['default'].element('<div>' + templateString + '</div>');
  1323. var ngModelNodes = templateEl[0].querySelectorAll('[ng-model],[data-ng-model]');
  1324. if (ngModelNodes.length) {
  1325. _angularFix2['default'].forEach(ngModelNodes, function (ngModelNode) {
  1326. fieldCount++;
  1327. watchFieldNameOrExistence(ngModelNode.getAttribute('name'));
  1328. });
  1329. }
  1330. function watchFieldNameOrExistence(name) {
  1331. var nameExpressionRegex = /\{\{(.*?)}}/;
  1332. var nameExpression = nameExpressionRegex.exec(name);
  1333. if (nameExpression) {
  1334. name = $interpolate(name)(scope);
  1335. }
  1336. watchFieldExistence(name);
  1337. }
  1338. function watchFieldExistence(name) {
  1339. scope.$watch('form["' + name + '"]', function formControlChange(formControl) {
  1340. if (formControl) {
  1341. if (fieldCount > 1) {
  1342. if (!scope.options.formControl) {
  1343. scope.options.formControl = [];
  1344. }
  1345. scope.options.formControl.push(formControl);
  1346. } else {
  1347. scope.options.formControl = formControl;
  1348. }
  1349. scope.fc = scope.options.formControl; // shortcut for template authors
  1350. stopWatchingShowError();
  1351. addShowMessagesWatcher();
  1352. addParsers();
  1353. addFormatters();
  1354. }
  1355. });
  1356. }
  1357. function addShowMessagesWatcher() {
  1358. stopWatchingShowError = scope.$watch(function watchShowValidationChange() {
  1359. var customExpression = formlyConfig.extras.errorExistsAndShouldBeVisibleExpression;
  1360. var options = scope.options;
  1361. var formControls = arrayify(scope.fc);
  1362. if (!formControls.some(function (fc) {
  1363. return fc.$invalid;
  1364. })) {
  1365. return false;
  1366. } else if (typeof options.validation.show === 'boolean') {
  1367. return options.validation.show;
  1368. } else if (customExpression) {
  1369. return formControls.some(function (fc) {
  1370. return formlyUtil.formlyEval(scope, customExpression, fc.$modelValue, fc.$viewValue);
  1371. });
  1372. } else {
  1373. return formControls.some(function (fc) {
  1374. var noTouchedButDirty = _angularFix2['default'].isUndefined(fc.$touched) && fc.$dirty;
  1375. return fc.$touched || noTouchedButDirty;
  1376. });
  1377. }
  1378. }, function onShowValidationChange(show) {
  1379. scope.options.validation.errorExistsAndShouldBeVisible = show;
  1380. scope.showError = show; // shortcut for template authors
  1381. });
  1382. }
  1383. function addParsers() {
  1384. setParsersOrFormatters('parsers');
  1385. }
  1386. function addFormatters() {
  1387. setParsersOrFormatters('formatters');
  1388. var ctrl = scope.fc;
  1389. var formWasPristine = scope.form.$pristine;
  1390. if (scope.options.formatters) {
  1391. (function () {
  1392. var value = ctrl.$modelValue;
  1393. ctrl.$formatters.forEach(function (formatter) {
  1394. value = formatter(value);
  1395. });
  1396. ctrl.$setViewValue(value);
  1397. ctrl.$render();
  1398. ctrl.$setPristine();
  1399. if (formWasPristine) {
  1400. scope.form.$setPristine();
  1401. }
  1402. })();
  1403. }
  1404. }
  1405. function setParsersOrFormatters(which) {
  1406. var originalThingProp = 'originalParser';
  1407. if (which === 'formatters') {
  1408. originalThingProp = 'originalFormatter';
  1409. }
  1410. // init with type's parsers
  1411. var things = getThingsFromType(type);
  1412. // get optionsTypes things
  1413. things = formlyUtil.extendArray(things, getThingsFromOptionsTypes(scope.options.optionsTypes));
  1414. // get field's things
  1415. things = formlyUtil.extendArray(things, scope.options[which]);
  1416. // convert things into formlyExpression things
  1417. _angularFix2['default'].forEach(things, function (thing, index) {
  1418. things[index] = getFormlyExpressionThing(thing);
  1419. });
  1420. var ngModelCtrls = scope.fc;
  1421. if (!_angularFix2['default'].isArray(ngModelCtrls)) {
  1422. ngModelCtrls = [ngModelCtrls];
  1423. }
  1424. _angularFix2['default'].forEach(ngModelCtrls, function (ngModelCtrl) {
  1425. var _ngModelCtrl;
  1426. ngModelCtrl['$' + which] = (_ngModelCtrl = ngModelCtrl['$' + which]).concat.apply(_ngModelCtrl, _toConsumableArray(things));
  1427. });
  1428. function getThingsFromType(theType) {
  1429. if (!theType) {
  1430. return [];
  1431. }
  1432. if (_angularFix2['default'].isString(theType)) {
  1433. theType = formlyConfig.getType(theType, true, scope.options);
  1434. }
  1435. var typeThings = [];
  1436. // get things from parent
  1437. if (theType['extends']) {
  1438. typeThings = formlyUtil.extendArray(typeThings, getThingsFromType(theType['extends']));
  1439. }
  1440. // get own type's things
  1441. typeThings = formlyUtil.extendArray(typeThings, getDefaultOptionsProperty(theType, which, []));
  1442. // get things from optionsTypes
  1443. typeThings = formlyUtil.extendArray(typeThings, getThingsFromOptionsTypes(getDefaultOptionsOptionsTypes(theType)));
  1444. return typeThings;
  1445. }
  1446. function getThingsFromOptionsTypes() {
  1447. var optionsTypes = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
  1448. var optionsTypesThings = [];
  1449. _angularFix2['default'].forEach(_angularFix2['default'].copy(arrayify(optionsTypes)).reverse(), function (optionsTypeName) {
  1450. optionsTypesThings = formlyUtil.extendArray(optionsTypesThings, getThingsFromType(optionsTypeName));
  1451. });
  1452. return optionsTypesThings;
  1453. }
  1454. function getFormlyExpressionThing(thing) {
  1455. formlyExpressionParserOrFormatterFunction[originalThingProp] = thing;
  1456. return formlyExpressionParserOrFormatterFunction;
  1457. function formlyExpressionParserOrFormatterFunction($viewValue) {
  1458. var $modelValue = scope.options.value();
  1459. return formlyUtil.formlyEval(scope, thing, $modelValue, $viewValue);
  1460. }
  1461. }
  1462. }
  1463. }
  1464. function callLinkFunctions() {
  1465. if (type && type.link) {
  1466. type.link.apply(thusly, args);
  1467. }
  1468. if (scope.options.link) {
  1469. scope.options.link.apply(thusly, args);
  1470. }
  1471. }
  1472. function runManipulators(manipulators) {
  1473. return function runManipulatorsOnTemplate(templateToManipulate) {
  1474. var chain = $q.when(templateToManipulate);
  1475. _angularFix2['default'].forEach(manipulators, function (manipulator) {
  1476. chain = chain.then(function (template) {
  1477. return $q.when(manipulator(template, scope.options, scope)).then(function (newTemplate) {
  1478. return _angularFix2['default'].isString(newTemplate) ? newTemplate : asHtml(newTemplate);
  1479. });
  1480. });
  1481. });
  1482. return chain;
  1483. };
  1484. }
  1485. }
  1486. // sort-of stateless util functions
  1487. function asHtml(el) {
  1488. var wrapper = _angularFix2['default'].element('<a></a>');
  1489. return wrapper.append(el).html();
  1490. }
  1491. function getFieldType(options) {
  1492. return options.type && formlyConfig.getType(options.type);
  1493. }
  1494. function getManipulators(options, formOptions) {
  1495. var preWrapper = [];
  1496. var postWrapper = [];
  1497. addManipulators(options.templateManipulators);
  1498. addManipulators(formOptions.templateManipulators);
  1499. addManipulators(formlyConfig.templateManipulators);
  1500. return { preWrapper: preWrapper, postWrapper: postWrapper };
  1501. function addManipulators(manipulators) {
  1502. /* eslint-disable */ // it doesn't understand this :-(
  1503. var _ref = manipulators || {};
  1504. var _ref$preWrapper = _ref.preWrapper;
  1505. var pre = _ref$preWrapper === undefined ? [] : _ref$preWrapper;
  1506. var _ref$postWrapper = _ref.postWrapper;
  1507. var post = _ref$postWrapper === undefined ? [] : _ref$postWrapper;
  1508. preWrapper = preWrapper.concat(pre);
  1509. postWrapper = postWrapper.concat(post);
  1510. /* eslint-enable */
  1511. }
  1512. }
  1513. function getFieldTemplate(options) {
  1514. function fromOptionsOrType(key, fieldType) {
  1515. if (_angularFix2['default'].isDefined(options[key])) {
  1516. return options[key];
  1517. } else if (fieldType && _angularFix2['default'].isDefined(fieldType[key])) {
  1518. return fieldType[key];
  1519. }
  1520. }
  1521. var type = formlyConfig.getType(options.type, true, options);
  1522. var template = fromOptionsOrType('template', type);
  1523. var templateUrl = fromOptionsOrType('templateUrl', type);
  1524. if (_angularFix2['default'].isUndefined(template) && !templateUrl) {
  1525. throw formlyUsability.getFieldError('type-type-has-no-template', 'Type \'' + options.type + '\' has no template. On element:', options);
  1526. }
  1527. return getTemplate(templateUrl || template, _angularFix2['default'].isUndefined(template), options);
  1528. }
  1529. function getTemplate(template, isUrl, options) {
  1530. var templatePromise = undefined;
  1531. if (_angularFix2['default'].isFunction(template)) {
  1532. templatePromise = $q.when(template(options));
  1533. } else {
  1534. templatePromise = $q.when(template);
  1535. }
  1536. if (!isUrl) {
  1537. return templatePromise;
  1538. } else {
  1539. var _ret3 = (function () {
  1540. var httpOptions = { cache: $templateCache };
  1541. return {
  1542. v: templatePromise.then(function (url) {
  1543. return $http.get(url, httpOptions);
  1544. }).then(function (response) {
  1545. return response.data;
  1546. })['catch'](function handleErrorGettingATemplate(error) {
  1547. formlyWarn('problem-loading-template-for-templateurl', 'Problem loading template for ' + template, error);
  1548. })
  1549. };
  1550. })();
  1551. if (typeof _ret3 === 'object') return _ret3.v;
  1552. }
  1553. }
  1554. function transcludeInWrappers(options, formOptions) {
  1555. var wrapper = getWrapperOption(options, formOptions);
  1556. return function transcludeTemplate(template) {
  1557. if (!wrapper.length) {
  1558. return $q.when(template);
  1559. }
  1560. wrapper.forEach(function (aWrapper) {
  1561. formlyUsability.checkWrapper(aWrapper, options);
  1562. runApiCheck(aWrapper, options);
  1563. });
  1564. var promises = wrapper.map(function (w) {
  1565. return getTemplate(w.template || w.templateUrl, !w.template);
  1566. });
  1567. return $q.all(promises).then(function (wrappersTemplates) {
  1568. wrappersTemplates.forEach(function (wrapperTemplate, index) {
  1569. formlyUsability.checkWrapperTemplate(wrapperTemplate, wrapper[index]);
  1570. });
  1571. wrappersTemplates.reverse(); // wrapper 0 is wrapped in wrapper 1 and so on...
  1572. var totalWrapper = wrappersTemplates.shift();
  1573. wrappersTemplates.forEach(function (wrapperTemplate) {
  1574. totalWrapper = doTransclusion(totalWrapper, wrapperTemplate);
  1575. });
  1576. return doTransclusion(totalWrapper, template);
  1577. });
  1578. };
  1579. }
  1580. function doTransclusion(wrapper, template) {
  1581. var superWrapper = _angularFix2['default'].element('<a></a>'); // this allows people not have to have a single root in wrappers
  1582. superWrapper.append(wrapper);
  1583. var transcludeEl = superWrapper.find('formly-transclude');
  1584. if (!transcludeEl.length) {
  1585. // try it using our custom find function
  1586. transcludeEl = formlyUtil.findByNodeName(superWrapper, 'formly-transclude');
  1587. }
  1588. transcludeEl.replaceWith(template);
  1589. return superWrapper.html();
  1590. }
  1591. function getWrapperOption(options, formOptions) {
  1592. /* eslint complexity:[2, 6] */
  1593. var wrapper = options.wrapper;
  1594. // explicit null means no wrapper
  1595. if (wrapper === null) {
  1596. return [];
  1597. }
  1598. // nothing specified means use the default wrapper for the type
  1599. if (!wrapper) {
  1600. // get all wrappers that specify they apply to this type
  1601. wrapper = arrayify(formlyConfig.getWrapperByType(options.type));
  1602. } else {
  1603. wrapper = arrayify(wrapper).map(formlyConfig.getWrapper);
  1604. }
  1605. // get all wrappers for that the type specified that it uses.
  1606. var type = formlyConfig.getType(options.type, true, options);
  1607. if (type && type.wrapper) {
  1608. var typeWrappers = arrayify(type.wrapper).map(formlyConfig.getWrapper);
  1609. wrapper = wrapper.concat(typeWrappers);
  1610. }
  1611. // add form wrappers
  1612. if (formOptions.wrapper) {
  1613. var formWrappers = arrayify(formOptions.wrapper).map(formlyConfig.getWrapper);
  1614. wrapper = wrapper.concat(formWrappers);
  1615. }
  1616. // add the default wrapper last
  1617. var defaultWrapper = formlyConfig.getWrapper();
  1618. if (defaultWrapper) {
  1619. wrapper.push(defaultWrapper);
  1620. }
  1621. return wrapper;
  1622. }
  1623. function checkApi(options) {
  1624. formlyApiCheck['throw'](formlyApiCheck.formlyFieldOptions, options, {
  1625. prefix: 'formly-field directive',
  1626. url: 'formly-field-directive-validation-failed'
  1627. });
  1628. // validate with the type
  1629. var type = options.type && formlyConfig.getType(options.type);
  1630. if (type) {
  1631. runApiCheck(type, options, true);
  1632. }
  1633. if (options.expressionProperties && options.expressionProperties.hide) {
  1634. formlyWarn('dont-use-expressionproperties.hide-use-hideexpression-instead', 'You have specified `hide` in `expressionProperties`. Use `hideExpression` instead', options);
  1635. }
  1636. }
  1637. function checkFieldGroupApi(options) {
  1638. formlyApiCheck['throw'](formlyApiCheck.fieldGroup, options, {
  1639. prefix: 'formly-field directive',
  1640. url: 'formly-field-directive-validation-failed'
  1641. });
  1642. }
  1643. function runApiCheck(_ref2, options, forType) {
  1644. var apiCheck = _ref2.apiCheck;
  1645. var apiCheckInstance = _ref2.apiCheckInstance;
  1646. var apiCheckFunction = _ref2.apiCheckFunction;
  1647. var apiCheckOptions = _ref2.apiCheckOptions;
  1648. runApiCheckForType(apiCheck, apiCheckInstance, apiCheckFunction, apiCheckOptions, options);
  1649. if (forType && options.type) {
  1650. _angularFix2['default'].forEach(formlyConfig.getTypeHeritage(options.type), function (type) {
  1651. runApiCheckForType(type.apiCheck, type.apiCheckInstance, type.apiCheckFunction, type.apiCheckOptions, options);
  1652. });
  1653. }
  1654. }
  1655. function runApiCheckForType(apiCheck, apiCheckInstance, apiCheckFunction, apiCheckOptions, options) {
  1656. /* eslint complexity:[2, 9] */
  1657. if (!apiCheck) {
  1658. return;
  1659. }
  1660. var instance = apiCheckInstance || formlyConfig.extras.apiCheckInstance || formlyApiCheck;
  1661. if (instance.config.disabled || _apiCheck2['default'].globalConfig.disabled) {
  1662. return;
  1663. }
  1664. var fn = apiCheckFunction || 'warn';
  1665. // this is the new API
  1666. var checkerObjects = apiCheck(instance);
  1667. _angularFix2['default'].forEach(checkerObjects, function (shape, name) {
  1668. var checker = instance.shape(shape);
  1669. var checkOptions = _angularFix2['default'].extend({
  1670. prefix: 'formly-field type ' + options.type + ' for property ' + name,
  1671. url: formlyApiCheck.config.output.docsBaseUrl + 'formly-field-type-apicheck-failed'
  1672. }, apiCheckOptions);
  1673. instance[fn](checker, options[name], checkOptions);
  1674. });
  1675. }
  1676. }
  1677. // Stateless util functions
  1678. function getDefaultOptionsOptionsTypes(type) {
  1679. return getDefaultOptionsProperty(type, 'optionsTypes', []);
  1680. }
  1681. function getDefaultOptionsProperty(type, prop, defaultValue) {
  1682. return type.defaultOptions && type.defaultOptions[prop] || defaultValue;
  1683. }
  1684. module.exports = exports['default'];
  1685. /***/ },
  1686. /* 15 */
  1687. /***/ function(module, exports) {
  1688. 'use strict';
  1689. formlyFocus.$inject = ["$timeout", "$document"];
  1690. Object.defineProperty(exports, '__esModule', {
  1691. value: true
  1692. });
  1693. exports['default'] = formlyFocus;
  1694. // @ngInject
  1695. function formlyFocus($timeout, $document) {
  1696. return {
  1697. restrict: 'A',
  1698. link: function formlyFocusLink(scope, element, attrs) {
  1699. var previousEl = null;
  1700. var el = element[0];
  1701. var doc = $document[0];
  1702. attrs.$observe('formlyFocus', function respondToFocusExpressionChange(value) {
  1703. /* eslint no-bitwise:0 */ // I know what I'm doing. I promise...
  1704. if (value === 'true') {
  1705. $timeout(function setElementFocus() {
  1706. previousEl = doc.activeElement;
  1707. el.focus();
  1708. }, ~ ~attrs.focusWait);
  1709. } else if (value === 'false') {
  1710. if (doc.activeElement === el) {
  1711. el.blur();
  1712. if (attrs.hasOwnProperty('refocus') && previousEl) {
  1713. previousEl.focus();
  1714. }
  1715. }
  1716. }
  1717. });
  1718. }
  1719. };
  1720. }
  1721. module.exports = exports['default'];
  1722. /***/ },
  1723. /* 16 */
  1724. /***/ function(module, exports, __webpack_require__) {
  1725. 'use strict';
  1726. formlyForm.$inject = ["formlyUsability", "formlyWarn", "$parse", "formlyConfig", "$interpolate"];
  1727. Object.defineProperty(exports, '__esModule', {
  1728. value: true
  1729. });
  1730. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  1731. var _angularFix = __webpack_require__(2);
  1732. var _angularFix2 = _interopRequireDefault(_angularFix);
  1733. exports['default'] = formlyForm;
  1734. /**
  1735. * @ngdoc directive
  1736. * @name formlyForm
  1737. * @restrict AE
  1738. */
  1739. // @ngInject
  1740. function formlyForm(formlyUsability, formlyWarn, $parse, formlyConfig, $interpolate) {
  1741. var currentFormId = 1;
  1742. return {
  1743. restrict: 'AE',
  1744. template: formlyFormGetTemplate,
  1745. replace: true,
  1746. transclude: true,
  1747. scope: {
  1748. fields: '=',
  1749. model: '=',
  1750. form: '=?',
  1751. options: '=?'
  1752. },
  1753. controller: 'FormlyFormController',
  1754. link: formlyFormLink
  1755. };
  1756. function formlyFormGetTemplate(el, attrs) {
  1757. var rootEl = getRootEl();
  1758. var fieldRootEl = getFieldRootEl();
  1759. var formId = 'formly_' + currentFormId++;
  1760. var parentFormAttributes = '';
  1761. if (attrs.hasOwnProperty('isFieldGroup') && el.parent().parent().hasClass('formly')) {
  1762. parentFormAttributes = copyAttributes(el.parent().parent()[0].attributes);
  1763. }
  1764. 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 ';
  1765. function getRootEl() {
  1766. return attrs.rootEl || 'ng-form';
  1767. }
  1768. function getFieldRootEl() {
  1769. return attrs.fieldRootEl || 'div';
  1770. }
  1771. function getHideDirective() {
  1772. return attrs.hideDirective || formlyConfig.extras.defaultHideDirective || 'ng-if';
  1773. }
  1774. function getTrackBy() {
  1775. if (!attrs.trackBy) {
  1776. return '';
  1777. } else {
  1778. return 'track by ' + attrs.trackBy;
  1779. }
  1780. }
  1781. function getFormName() {
  1782. var formName = formId;
  1783. var bindName = attrs.bindName;
  1784. if (bindName) {
  1785. if (_angularFix2['default'].version.minor < 3) {
  1786. throw formlyUsability.getFormlyError('bind-name attribute on formly-form not allowed in < angular 1.3');
  1787. }
  1788. // we can do a one-time binding here because we know we're in 1.3.x territory
  1789. formName = $interpolate.startSymbol() + '::\'formly_\' + ' + bindName + $interpolate.endSymbol();
  1790. }
  1791. return formName;
  1792. }
  1793. function getTranscludeClass() {
  1794. return attrs.transcludeClass || '';
  1795. }
  1796. function copyAttributes(attributes) {
  1797. var excluded = ['model', 'form', 'fields', 'options', 'name', 'role', 'class', 'data-model', 'data-form', 'data-fields', 'data-options', 'data-name'];
  1798. var arrayAttrs = [];
  1799. _angularFix2['default'].forEach(attributes, function (_ref) {
  1800. var nodeName = _ref.nodeName;
  1801. var value = _ref.value;
  1802. if (nodeName !== 'undefined' && excluded.indexOf(nodeName) === -1) {
  1803. arrayAttrs.push(toKebabCase(nodeName) + '="' + value + '"');
  1804. }
  1805. });
  1806. return arrayAttrs.join(' ');
  1807. }
  1808. }
  1809. function formlyFormLink(scope, el, attrs) {
  1810. setFormController();
  1811. fixChromeAutocomplete();
  1812. function setFormController() {
  1813. var formId = attrs.name;
  1814. scope.formId = formId;
  1815. scope.theFormlyForm = scope[formId];
  1816. if (attrs.form) {
  1817. var getter = $parse(attrs.form);
  1818. var setter = getter.assign;
  1819. var parentForm = getter(scope.$parent);
  1820. if (parentForm) {
  1821. scope.theFormlyForm = parentForm;
  1822. if (scope[formId]) {
  1823. scope.theFormlyForm.$removeControl(scope[formId]);
  1824. }
  1825. // this next line is probably one of the more dangerous things that angular-formly does to improve the
  1826. // API for angular-formly forms. It ensures that the NgModelControllers inside of formly-form will be
  1827. // attached to the form that is passed to formly-form rather than the one that formly-form creates
  1828. // this is necessary because it's confusing to have a step between the form you pass in
  1829. // and the fields in that form. It also is because angular doesn't propagate properties like $submitted down
  1830. // to children forms :-( This line was added to solve this issue:
  1831. // https://github.com/formly-js/angular-formly/issues/287
  1832. // luckily, this is how the formController has been accessed by the NgModelController since angular 1.0.0
  1833. // so I expect it will remain this way for the life of angular 1.x
  1834. el.removeData('$formController');
  1835. } else {
  1836. setter(scope.$parent, scope[formId]);
  1837. }
  1838. }
  1839. if (!scope.theFormlyForm && !formlyConfig.disableWarnings) {
  1840. /* eslint no-console:0 */
  1841. formlyWarn('formly-form-has-no-formcontroller', 'Your formly-form does not have a `form` property. Many functions of the form (like validation) may not work', el, scope);
  1842. }
  1843. }
  1844. /*
  1845. * chrome autocomplete lameness
  1846. * see https://code.google.com/p/chromium/issues/detail?id=468153#c14
  1847. * ლ(ಠ益ಠლ) (╯°□°)╯︵ ┻━┻ (◞‸◟;)
  1848. */
  1849. function fixChromeAutocomplete() {
  1850. var global = formlyConfig.extras.removeChromeAutoComplete === true;
  1851. var offInstance = scope.options && scope.options.removeChromeAutoComplete === false;
  1852. var onInstance = scope.options && scope.options.removeChromeAutoComplete === true;
  1853. if (global && !offInstance || onInstance) {
  1854. var input = document.createElement('input');
  1855. input.setAttribute('autocomplete', 'address-level4');
  1856. input.setAttribute('hidden', 'true');
  1857. el[0].appendChild(input);
  1858. }
  1859. }
  1860. }
  1861. // stateless util functions
  1862. function toKebabCase(string) {
  1863. if (string) {
  1864. return string.replace(/([A-Z])/g, function ($1) {
  1865. return '-' + $1.toLowerCase();
  1866. });
  1867. } else {
  1868. return '';
  1869. }
  1870. }
  1871. }
  1872. module.exports = exports['default'];
  1873. /***/ },
  1874. /* 17 */
  1875. /***/ function(module, exports, __webpack_require__) {
  1876. 'use strict';
  1877. FormlyFormController.$inject = ["formlyUsability", "formlyWarn", "formlyConfig", "$parse", "$scope", "formlyApiCheck", "formlyUtil"];
  1878. Object.defineProperty(exports, '__esModule', {
  1879. value: true
  1880. });
  1881. var _slice = Array.prototype.slice;
  1882. exports['default'] = FormlyFormController;
  1883. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  1884. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
  1885. var _angularFix = __webpack_require__(2);
  1886. var _angularFix2 = _interopRequireDefault(_angularFix);
  1887. function isFieldGroup(field) {
  1888. return field && !!field.fieldGroup;
  1889. }
  1890. // @ngInject
  1891. function FormlyFormController(formlyUsability, formlyWarn, formlyConfig, $parse, $scope, formlyApiCheck, formlyUtil) {
  1892. setupOptions();
  1893. $scope.model = $scope.model || {};
  1894. setupFields();
  1895. // watch the model and evaluate watch expressions that depend on it.
  1896. if (!$scope.options.manualModelWatcher) {
  1897. $scope.$watch('model', onModelOrFormStateChange, true);
  1898. } else if (_angularFix2['default'].isFunction($scope.options.manualModelWatcher)) {
  1899. $scope.$watch($scope.options.manualModelWatcher, onModelOrFormStateChange, true);
  1900. }
  1901. if ($scope.options.formState) {
  1902. $scope.$watch('options.formState', onModelOrFormStateChange, true);
  1903. }
  1904. function onModelOrFormStateChange() {
  1905. _angularFix2['default'].forEach($scope.fields, runFieldExpressionProperties);
  1906. }
  1907. function validateFormControl(formControl, promise) {
  1908. var validate = formControl.$validate;
  1909. if (promise) {
  1910. promise.then(function () {
  1911. return validate.apply(formControl);
  1912. });
  1913. } else {
  1914. validate();
  1915. }
  1916. }
  1917. function runFieldExpressionProperties(field, index) {
  1918. var model = field.model || $scope.model;
  1919. var promise = field.runExpressions && field.runExpressions();
  1920. if (field.hideExpression) {
  1921. // can't use hide with expressionProperties reliably
  1922. var val = model[field.key];
  1923. field.hide = evalCloseToFormlyExpression(field.hideExpression, val, field, index, { model: model });
  1924. }
  1925. if (field.extras && field.extras.validateOnModelChange && field.formControl) {
  1926. if (_angularFix2['default'].isArray(field.formControl)) {
  1927. _angularFix2['default'].forEach(field.formControl, function (formControl) {
  1928. validateFormControl(formControl, promise);
  1929. });
  1930. } else {
  1931. validateFormControl(field.formControl, promise);
  1932. }
  1933. }
  1934. }
  1935. function setupFields() {
  1936. $scope.fields = $scope.fields || [];
  1937. checkDeprecatedOptions($scope.options);
  1938. var fieldTransforms = $scope.options.fieldTransform || formlyConfig.extras.fieldTransform;
  1939. if (!_angularFix2['default'].isArray(fieldTransforms)) {
  1940. fieldTransforms = [fieldTransforms];
  1941. }
  1942. _angularFix2['default'].forEach(fieldTransforms, function transformFields(fieldTransform) {
  1943. if (fieldTransform) {
  1944. $scope.fields = fieldTransform($scope.fields, $scope.model, $scope.options, $scope.form);
  1945. if (!$scope.fields) {
  1946. throw formlyUsability.getFormlyError('fieldTransform must return an array of fields');
  1947. }
  1948. }
  1949. });
  1950. setupModels();
  1951. if ($scope.options.watchAllExpressions) {
  1952. _angularFix2['default'].forEach($scope.fields, setupHideExpressionWatcher);
  1953. }
  1954. _angularFix2['default'].forEach($scope.fields, attachKey); // attaches a key based on the index if a key isn't specified
  1955. _angularFix2['default'].forEach($scope.fields, setupWatchers); // setup watchers for all fields
  1956. }
  1957. function checkDeprecatedOptions(options) {
  1958. if (formlyConfig.extras.fieldTransform && _angularFix2['default'].isFunction(formlyConfig.extras.fieldTransform)) {
  1959. formlyWarn('fieldtransform-as-a-function-deprecated', 'fieldTransform as a function has been deprecated.', 'Attempted for formlyConfig.extras: ' + formlyConfig.extras.fieldTransform.name, formlyConfig.extras);
  1960. } else if (options.fieldTransform && _angularFix2['default'].isFunction(options.fieldTransform)) {
  1961. formlyWarn('fieldtransform-as-a-function-deprecated', 'fieldTransform as a function has been deprecated.', 'Attempted for form', options);
  1962. }
  1963. }
  1964. function setupOptions() {
  1965. formlyApiCheck['throw']([formlyApiCheck.formOptionsApi.optional], [$scope.options], { prefix: 'formly-form options check' });
  1966. $scope.options = $scope.options || {};
  1967. $scope.options.formState = $scope.options.formState || {};
  1968. _angularFix2['default'].extend($scope.options, {
  1969. updateInitialValue: updateInitialValue,
  1970. resetModel: resetModel
  1971. });
  1972. }
  1973. function updateInitialValue() {
  1974. _angularFix2['default'].forEach($scope.fields, function (field) {
  1975. if (isFieldGroup(field) && field.options) {
  1976. field.options.updateInitialValue();
  1977. } else {
  1978. field.updateInitialValue();
  1979. }
  1980. });
  1981. }
  1982. function resetModel() {
  1983. _angularFix2['default'].forEach($scope.fields, function (field) {
  1984. if (isFieldGroup(field) && field.options) {
  1985. field.options.resetModel();
  1986. } else if (field.resetModel) {
  1987. field.resetModel();
  1988. }
  1989. });
  1990. }
  1991. function setupModels() {
  1992. // a set of field models that are already watched (the $scope.model will have its own watcher)
  1993. var watchedModels = [$scope.model];
  1994. // we will not set up automatic model watchers if manual mode is set
  1995. var manualModelWatcher = $scope.options.manualModelWatcher;
  1996. if ($scope.options.formState) {
  1997. // $scope.options.formState will have its own watcher
  1998. watchedModels.push($scope.options.formState);
  1999. }
  2000. _angularFix2['default'].forEach($scope.fields, function (field) {
  2001. var isNewModel = initModel(field);
  2002. if (field.model && isNewModel && watchedModels.indexOf(field.model) === -1 && !manualModelWatcher) {
  2003. $scope.$watch(function () {
  2004. return field.model;
  2005. }, onModelOrFormStateChange, true);
  2006. watchedModels.push(field.model);
  2007. }
  2008. });
  2009. }
  2010. function setupHideExpressionWatcher(field, index) {
  2011. if (field.hideExpression) {
  2012. (function () {
  2013. // can't use hide with expressionProperties reliably
  2014. var model = field.model || $scope.model;
  2015. $scope.$watch(function hideExpressionWatcher() {
  2016. var val = model[field.key];
  2017. return evalCloseToFormlyExpression(field.hideExpression, val, field, index, { model: model });
  2018. }, function (hide) {
  2019. return field.hide = hide;
  2020. }, true);
  2021. })();
  2022. }
  2023. }
  2024. function initModel(field) {
  2025. var isNewModel = true;
  2026. if (_angularFix2['default'].isString(field.model)) {
  2027. (function () {
  2028. var expression = field.model;
  2029. isNewModel = !referencesCurrentlyWatchedModel(expression);
  2030. field.model = resolveStringModel(expression);
  2031. $scope.$watch(function () {
  2032. return resolveStringModel(expression);
  2033. }, function (model) {
  2034. return field.model = model;
  2035. });
  2036. })();
  2037. }
  2038. return isNewModel;
  2039. function resolveStringModel(expression) {
  2040. var index = $scope.fields.indexOf(field);
  2041. var model = evalCloseToFormlyExpression(expression, undefined, field, index, { model: $scope.model });
  2042. if (!model) {
  2043. 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);
  2044. }
  2045. return model;
  2046. }
  2047. }
  2048. function referencesCurrentlyWatchedModel(expression) {
  2049. return ['model', 'formState'].some(function (item) {
  2050. return formlyUtil.startsWith(expression, item + '.') || formlyUtil.startsWith(expression, item + '[');
  2051. });
  2052. }
  2053. function attachKey(field, index) {
  2054. if (!isFieldGroup(field)) {
  2055. field.key = field.key || index || 0;
  2056. }
  2057. }
  2058. function setupWatchers(field, index) {
  2059. if (!_angularFix2['default'].isDefined(field.watcher)) {
  2060. return;
  2061. }
  2062. var watchers = field.watcher;
  2063. if (!_angularFix2['default'].isArray(watchers)) {
  2064. watchers = [watchers];
  2065. }
  2066. _angularFix2['default'].forEach(watchers, function setupWatcher(watcher) {
  2067. if (!_angularFix2['default'].isDefined(watcher.listener) && !watcher.runFieldExpressions) {
  2068. throw formlyUsability.getFieldError('all-field-watchers-must-have-a-listener', 'All field watchers must have a listener', field);
  2069. }
  2070. var watchExpression = getWatchExpression(watcher, field, index);
  2071. var watchListener = getWatchListener(watcher, field, index);
  2072. var type = watcher.type || '$watch';
  2073. watcher.stopWatching = $scope[type](watchExpression, watchListener, watcher.watchDeep);
  2074. });
  2075. }
  2076. function getWatchExpression(watcher, field, index) {
  2077. var watchExpression = undefined;
  2078. if (!_angularFix2['default'].isUndefined(watcher.expression)) {
  2079. watchExpression = watcher.expression;
  2080. } else if (field.key) {
  2081. watchExpression = 'model[\'' + field.key.toString().split('.').join('\'][\'') + '\']';
  2082. }
  2083. if (_angularFix2['default'].isFunction(watchExpression)) {
  2084. (function () {
  2085. // wrap the field's watch expression so we can call it with the field as the first arg
  2086. // and the stop function as the last arg as a helper
  2087. var originalExpression = watchExpression;
  2088. watchExpression = function formlyWatchExpression() {
  2089. var args = modifyArgs.apply(undefined, [watcher, index].concat(_slice.call(arguments)));
  2090. return originalExpression.apply(undefined, _toConsumableArray(args));
  2091. };
  2092. watchExpression.displayName = 'Formly Watch Expression for field for ' + field.key;
  2093. })();
  2094. } else if (field.model) {
  2095. watchExpression = $parse(watchExpression).bind(null, $scope, { model: field.model });
  2096. }
  2097. return watchExpression;
  2098. }
  2099. function getWatchListener(watcher, field, index) {
  2100. var watchListener = watcher.listener;
  2101. if (_angularFix2['default'].isFunction(watchListener) || watcher.runFieldExpressions) {
  2102. (function () {
  2103. // wrap the field's watch listener so we can call it with the field as the first arg
  2104. // and the stop function as the last arg as a helper
  2105. var originalListener = watchListener;
  2106. watchListener = function formlyWatchListener() {
  2107. var value = undefined;
  2108. if (originalListener) {
  2109. var args = modifyArgs.apply(undefined, [watcher, index].concat(_slice.call(arguments)));
  2110. value = originalListener.apply(undefined, _toConsumableArray(args));
  2111. }
  2112. if (watcher.runFieldExpressions) {
  2113. runFieldExpressionProperties(field, index);
  2114. }
  2115. return value;
  2116. };
  2117. watchListener.displayName = 'Formly Watch Listener for field for ' + field.key;
  2118. })();
  2119. }
  2120. return watchListener;
  2121. }
  2122. function modifyArgs(watcher, index) {
  2123. for (var _len = arguments.length, originalArgs = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  2124. originalArgs[_key - 2] = arguments[_key];
  2125. }
  2126. return [$scope.fields[index]].concat(originalArgs, [watcher.stopWatching]);
  2127. }
  2128. function evalCloseToFormlyExpression(expression, val, field, index) {
  2129. var extraLocals = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4];
  2130. extraLocals = _angularFix2['default'].extend(getFormlyFieldLikeLocals(field, index), extraLocals);
  2131. return formlyUtil.formlyEval($scope, expression, val, val, extraLocals);
  2132. }
  2133. function getFormlyFieldLikeLocals(field, index) {
  2134. // this makes it closer to what a regular formlyExpression would be
  2135. return {
  2136. model: field.model,
  2137. options: field,
  2138. index: index,
  2139. formState: $scope.options.formState,
  2140. originalModel: $scope.model,
  2141. formOptions: $scope.options,
  2142. formId: $scope.formId
  2143. };
  2144. }
  2145. }
  2146. module.exports = exports['default'];
  2147. /***/ },
  2148. /* 18 */
  2149. /***/ function(module, exports, __webpack_require__) {
  2150. 'use strict';
  2151. addFormlyNgModelAttrsManipulator.$inject = ["formlyConfig", "$interpolate"];
  2152. Object.defineProperty(exports, '__esModule', {
  2153. value: true
  2154. });
  2155. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2156. var _angularFix = __webpack_require__(2);
  2157. var _angularFix2 = _interopRequireDefault(_angularFix);
  2158. var _otherUtils = __webpack_require__(9);
  2159. exports['default'] = addFormlyNgModelAttrsManipulator;
  2160. // @ngInject
  2161. function addFormlyNgModelAttrsManipulator(formlyConfig, $interpolate) {
  2162. if (formlyConfig.extras.disableNgModelAttrsManipulator) {
  2163. return;
  2164. }
  2165. formlyConfig.templateManipulators.preWrapper.push(ngModelAttrsManipulator);
  2166. function ngModelAttrsManipulator(template, options, scope) {
  2167. var node = document.createElement('div');
  2168. var skip = options.extras && options.extras.skipNgModelAttrsManipulator;
  2169. if (skip === true) {
  2170. return template;
  2171. }
  2172. node.innerHTML = template;
  2173. var modelNodes = getNgModelNodes(node, skip);
  2174. if (!modelNodes || !modelNodes.length) {
  2175. return template;
  2176. }
  2177. addIfNotPresent(modelNodes, 'id', scope.id);
  2178. addIfNotPresent(modelNodes, 'name', scope.name || scope.id);
  2179. addValidation();
  2180. alterNgModelAttr();
  2181. addModelOptions();
  2182. addTemplateOptionsAttrs();
  2183. addNgModelElAttrs();
  2184. return node.innerHTML;
  2185. function addValidation() {
  2186. if (_angularFix2['default'].isDefined(options.validators) || _angularFix2['default'].isDefined(options.validation.messages)) {
  2187. addIfNotPresent(modelNodes, 'formly-custom-validation', '');
  2188. }
  2189. }
  2190. function alterNgModelAttr() {
  2191. if (isPropertyAccessor(options.key)) {
  2192. addRegardlessOfPresence(modelNodes, 'ng-model', 'model.' + options.key);
  2193. }
  2194. }
  2195. function addModelOptions() {
  2196. if (_angularFix2['default'].isDefined(options.modelOptions)) {
  2197. addIfNotPresent(modelNodes, 'ng-model-options', 'options.modelOptions');
  2198. if (options.modelOptions.getterSetter) {
  2199. addRegardlessOfPresence(modelNodes, 'ng-model', 'options.value');
  2200. }
  2201. }
  2202. }
  2203. function addTemplateOptionsAttrs() {
  2204. if (!options.templateOptions && !options.expressionProperties) {
  2205. // no need to run these if there are no templateOptions or expressionProperties
  2206. return;
  2207. }
  2208. var to = options.templateOptions || {};
  2209. var ep = options.expressionProperties || {};
  2210. var ngModelAttributes = getBuiltInAttributes();
  2211. // extend with the user's specifications winning
  2212. _angularFix2['default'].extend(ngModelAttributes, options.ngModelAttrs);
  2213. // Feel free to make this more simple :-)
  2214. _angularFix2['default'].forEach(ngModelAttributes, function (val, name) {
  2215. /* eslint complexity:[2, 14] */
  2216. var attrVal = undefined,
  2217. attrName = undefined;
  2218. var ref = 'options.templateOptions[\'' + name + '\']';
  2219. var toVal = to[name];
  2220. var epVal = getEpValue(ep, name);
  2221. var inTo = _angularFix2['default'].isDefined(toVal);
  2222. var inEp = _angularFix2['default'].isDefined(epVal);
  2223. if (val.value) {
  2224. // I realize this looks backwards, but it's right, trust me...
  2225. attrName = val.value;
  2226. attrVal = name;
  2227. } else if (val.statement && inTo) {
  2228. attrName = val.statement;
  2229. if (_angularFix2['default'].isString(to[name])) {
  2230. attrVal = '$eval(' + ref + ')';
  2231. } else if (_angularFix2['default'].isFunction(to[name])) {
  2232. attrVal = ref + '(model[options.key], options, this, $event)';
  2233. } else {
  2234. throw new Error('options.templateOptions.' + name + ' must be a string or function: ' + JSON.stringify(options));
  2235. }
  2236. } else if (val.bound && inEp) {
  2237. attrName = val.bound;
  2238. attrVal = ref;
  2239. } else if ((val.attribute || val.boolean) && inEp) {
  2240. attrName = val.attribute || val.boolean;
  2241. attrVal = '' + $interpolate.startSymbol() + ref + $interpolate.endSymbol();
  2242. } else if (val.attribute && inTo) {
  2243. attrName = val.attribute;
  2244. attrVal = toVal;
  2245. } else if (val.boolean) {
  2246. if (inTo && !inEp && toVal) {
  2247. attrName = val.boolean;
  2248. attrVal = true;
  2249. } else {
  2250. /* eslint no-empty:0 */
  2251. // empty to illustrate that a boolean will not be added via val.bound
  2252. // if you want it added via val.bound, then put it in expressionProperties
  2253. }
  2254. } else if (val.bound && inTo) {
  2255. attrName = val.bound;
  2256. attrVal = ref;
  2257. }
  2258. if (_angularFix2['default'].isDefined(attrName) && _angularFix2['default'].isDefined(attrVal)) {
  2259. addIfNotPresent(modelNodes, attrName, attrVal);
  2260. }
  2261. });
  2262. }
  2263. function addNgModelElAttrs() {
  2264. _angularFix2['default'].forEach(options.ngModelElAttrs, function (val, name) {
  2265. addRegardlessOfPresence(modelNodes, name, val);
  2266. });
  2267. }
  2268. }
  2269. // Utility functions
  2270. function getNgModelNodes(node, skip) {
  2271. var selectorNot = _angularFix2['default'].isString(skip) ? ':not(' + skip + ')' : '';
  2272. var skipNot = ':not([formly-skip-ng-model-attrs-manipulator])';
  2273. var query = '[ng-model]' + selectorNot + skipNot + ', [data-ng-model]' + selectorNot + skipNot;
  2274. try {
  2275. return node.querySelectorAll(query);
  2276. } catch (e) {
  2277. //this code is needed for IE8, as it does not support the CSS3 ':not' selector
  2278. //it should be removed when IE8 support is dropped
  2279. return getNgModelNodesFallback(node, skip);
  2280. }
  2281. }
  2282. function getNgModelNodesFallback(node, skip) {
  2283. var allNgModelNodes = node.querySelectorAll('[ng-model], [data-ng-model]');
  2284. var matchingNgModelNodes = [];
  2285. //make sure this array is compatible with NodeList type by adding an 'item' function
  2286. matchingNgModelNodes.item = function (i) {
  2287. return this[i];
  2288. };
  2289. for (var i = 0; i < allNgModelNodes.length; i++) {
  2290. var ngModelNode = allNgModelNodes[i];
  2291. if (!ngModelNode.hasAttribute('formly-skip-ng-model-attrs-manipulator') && !(_angularFix2['default'].isString(skip) && nodeMatches(ngModelNode, skip))) {
  2292. matchingNgModelNodes.push(ngModelNode);
  2293. }
  2294. }
  2295. return matchingNgModelNodes;
  2296. }
  2297. function nodeMatches(node, selector) {
  2298. var div = document.createElement('div');
  2299. div.innerHTML = node.outerHTML;
  2300. return div.querySelector(selector);
  2301. }
  2302. function getBuiltInAttributes() {
  2303. var ngModelAttributes = {
  2304. focus: {
  2305. attribute: 'formly-focus'
  2306. }
  2307. };
  2308. var boundOnly = [];
  2309. var bothBooleanAndBound = ['required', 'disabled'];
  2310. var bothAttributeAndBound = ['pattern', 'minlength'];
  2311. var statementOnly = ['change', 'keydown', 'keyup', 'keypress', 'click', 'focus', 'blur'];
  2312. var attributeOnly = ['placeholder', 'min', 'max', 'step', 'tabindex', 'type'];
  2313. if (formlyConfig.extras.ngModelAttrsManipulatorPreferUnbound) {
  2314. bothAttributeAndBound.push('maxlength');
  2315. } else {
  2316. boundOnly.push('maxlength');
  2317. }
  2318. _angularFix2['default'].forEach(boundOnly, function (item) {
  2319. ngModelAttributes[item] = { bound: 'ng-' + item };
  2320. });
  2321. _angularFix2['default'].forEach(bothBooleanAndBound, function (item) {
  2322. ngModelAttributes[item] = { boolean: item, bound: 'ng-' + item };
  2323. });
  2324. _angularFix2['default'].forEach(bothAttributeAndBound, function (item) {
  2325. ngModelAttributes[item] = { attribute: item, bound: 'ng-' + item };
  2326. });
  2327. _angularFix2['default'].forEach(statementOnly, function (item) {
  2328. var propName = 'on' + item.substr(0, 1).toUpperCase() + item.substr(1);
  2329. ngModelAttributes[propName] = { statement: 'ng-' + item };
  2330. });
  2331. _angularFix2['default'].forEach(attributeOnly, function (item) {
  2332. ngModelAttributes[item] = { attribute: item };
  2333. });
  2334. return ngModelAttributes;
  2335. }
  2336. function getEpValue(ep, name) {
  2337. return ep['templateOptions.' + name] || ep['templateOptions[\'' + name + '\']'] || ep['templateOptions["' + name + '"]'];
  2338. }
  2339. function addIfNotPresent(nodes, attr, val) {
  2340. _angularFix2['default'].forEach(nodes, function (node) {
  2341. if (!node.getAttribute(attr)) {
  2342. node.setAttribute(attr, val);
  2343. }
  2344. });
  2345. }
  2346. function addRegardlessOfPresence(nodes, attr, val) {
  2347. _angularFix2['default'].forEach(nodes, function (node) {
  2348. node.setAttribute(attr, val);
  2349. });
  2350. }
  2351. function isPropertyAccessor(key) {
  2352. return (0, _otherUtils.contains)(key, '.') || (0, _otherUtils.contains)(key, '[') && (0, _otherUtils.contains)(key, ']');
  2353. }
  2354. }
  2355. module.exports = exports['default'];
  2356. /***/ },
  2357. /* 19 */
  2358. /***/ function(module, exports, __webpack_require__) {
  2359. 'use strict';
  2360. addCustomTags.$inject = ["$document"];
  2361. Object.defineProperty(exports, '__esModule', {
  2362. value: true
  2363. });
  2364. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2365. var _angularFix = __webpack_require__(2);
  2366. var _angularFix2 = _interopRequireDefault(_angularFix);
  2367. exports['default'] = addCustomTags;
  2368. // @ngInject
  2369. function addCustomTags($document) {
  2370. // IE8 check ->
  2371. // https://msdn.microsoft.com/en-us/library/cc196988(v=vs.85).aspx
  2372. if ($document && $document.documentMode < 9) {
  2373. (function () {
  2374. var document = $document.get(0);
  2375. // add the custom elements that we need for formly
  2376. var customElements = ['formly-field', 'formly-form'];
  2377. _angularFix2['default'].forEach(customElements, function (el) {
  2378. document.createElement(el);
  2379. });
  2380. })();
  2381. }
  2382. }
  2383. module.exports = exports['default'];
  2384. /***/ }
  2385. /******/ ])
  2386. });
  2387. ;