formly.js 138 KB

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