formly.js 94 KB

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