UNPKG

angular-formly

Version:

AngularJS directive which takes JSON representing a form and renders to HTML

1,371 lines (1,197 loc) 196 kB
// angular-formly version 4.2.2 built with ♥ by Astrism <astrisms@gmail.com>, Kent C. Dodds <kent@doddsfamily.us> (ó ì_í)=óò=(ì_í ò) (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("api-check"), require("angular")); else if(typeof define === 'function' && define.amd) define(["api-check", "angular"], factory); else if(typeof exports === 'object') exports["ngFormly"] = factory(require("api-check"), require("angular")); else root["ngFormly"] = factory(root["apiCheck"], root["angular"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_9__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = __webpack_require__(1); /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var apiCheck = __webpack_require__(2); if (!apiCheck) { throw new Error("angular-formly requires the library apiCheck.js! Please include it! " + __webpack_require__(3) + "apicheckjs-dependency-required"); } var ngModuleName = "formly"; var angular = __webpack_require__(4); var ngModule = angular.module(ngModuleName, []); __webpack_require__(5)(ngModule); __webpack_require__(6)(ngModule); __webpack_require__(7)(ngModule); __webpack_require__(8)(ngModule); module.exports = ngModuleName; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { module.exports = __WEBPACK_EXTERNAL_MODULE_2__; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = "https://github.com/formly-js/angular-formly/blob/" + ("4.2.2") + "/other/ERRORS_AND_WARNINGS.md#"; /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { "use strict"; // some versions of angular don't export the angular module properly, // so we get it from window in this case. var angular = __webpack_require__(9); if (!angular.version) { angular = window.angular; } module.exports = angular; /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { __webpack_require__(10)(ngModule); __webpack_require__(11)(ngModule); __webpack_require__(12)(ngModule); __webpack_require__(13)(ngModule); __webpack_require__(14)(ngModule); __webpack_require__(15)(ngModule); }; /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { __webpack_require__(16)(ngModule); __webpack_require__(17)(ngModule); }; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { __webpack_require__(18)(ngModule); __webpack_require__(19)(ngModule); __webpack_require__(20)(ngModule); __webpack_require__(21)(ngModule); }; /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { __webpack_require__(22)(ngModule); __webpack_require__(23)(ngModule); }; /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { module.exports = __WEBPACK_EXTERNAL_MODULE_9__; /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { var apiCheck = __webpack_require__(2)({ output: { prefix: "angular-formly:", docsBaseUrl: __webpack_require__(3) } }); function shapeRequiredIfNot(otherProps, propChecker) { if (!angular.isArray(otherProps)) { otherProps = [otherProps]; } var type = "specified if these are not specified: `" + otherProps.join(", ") + "` (otherwise it's optional)"; function shapeRequiredIfNotDefinition(prop, propName, location, obj) { var propExists = obj && obj.hasOwnProperty(propName); var otherPropsExist = otherProps.some(function (otherProp) { return obj && obj.hasOwnProperty(otherProp); }); //console.log(propName, propExists, prop, otherPropsExist, otherProps.join(', ')); if (!otherPropsExist && !propExists) { return apiCheck.utils.getError(propName, location, type); } else if (propExists) { return propChecker(prop, propName, location, obj); } } shapeRequiredIfNotDefinition.type = type; apiCheck.utils.checkerHelpers.setupChecker(shapeRequiredIfNotDefinition); return shapeRequiredIfNotDefinition; } ngModule.constant("formlyApiCheck", apiCheck); if (false) { require("./formlyApiCheck.test")(ngModule); } var formlyExpression = apiCheck.oneOfType([apiCheck.string, apiCheck.func]); var specifyWrapperType = apiCheck.oneOfType([apiCheck.oneOf([null]), apiCheck.typeOrArrayOf(apiCheck.string)]); var apiCheckProperty = apiCheck.objectOf(apiCheck.func); var apiCheckInstanceProperty = apiCheck.shape.onlyIf("apiCheck", apiCheck.func.withProperties({ warn: apiCheck.func, "throw": apiCheck.func, shape: apiCheck.func })); var apiCheckFunctionProperty = apiCheck.shape.onlyIf("apiCheck", apiCheck.oneOf(["throw", "warn"])); var formlyWrapperType = apiCheck.shape({ name: shapeRequiredIfNot("types", apiCheck.string).optional, template: apiCheck.shape.ifNot("templateUrl", apiCheck.string).optional, templateUrl: apiCheck.shape.ifNot("template", apiCheck.string).optional, types: apiCheck.typeOrArrayOf(apiCheck.string).optional, overwriteOk: apiCheck.bool.optional, validateOptions: apiCheck.func.optional, apiCheck: apiCheckProperty.optional, apiCheckInstance: apiCheckInstanceProperty.optional, apiCheckFunction: apiCheckFunctionProperty.optional, apiCheckOptions: apiCheck.object.optional }).strict; var fieldOptionsApiShape = { type: apiCheck.shape.ifNot(["template", "templateUrl"], apiCheck.string).optional, template: apiCheck.shape.ifNot(["type", "templateUrl"], apiCheck.string).optional, templateUrl: apiCheck.shape.ifNot(["type", "template"], apiCheck.string).optional, key: apiCheck.oneOfType([apiCheck.string, apiCheck.number]), model: apiCheck.object.optional, expressionProperties: apiCheck.objectOf(apiCheck.oneOfType([formlyExpression, apiCheck.shape({ expression: formlyExpression, message: formlyExpression.optional }).strict])).optional, data: apiCheck.object.optional, templateOptions: apiCheck.object.optional, wrapper: specifyWrapperType.optional, modelOptions: apiCheck.shape({ updateOn: apiCheck.string.optional, debounce: apiCheck.oneOfType([apiCheck.object, apiCheck.string]).optional, allowInvalid: apiCheck.bool.optional, getterSetter: apiCheck.bool.optional, timezone: apiCheck.string.optional }).optional, watcher: apiCheck.typeOrArrayOf(apiCheck.shape({ expression: formlyExpression.optional, listener: formlyExpression })).optional, validators: apiCheck.objectOf(apiCheck.oneOfType([formlyExpression, apiCheck.shape({ expression: formlyExpression, message: formlyExpression.optional }).strict])).optional, noFormControl: apiCheck.bool.optional, hide: apiCheck.bool.optional, ngModelAttrs: apiCheck.objectOf(apiCheck.shape({ expression: apiCheck.shape.ifNot(["value", "attribute", "bound"], apiCheck.any).optional, value: apiCheck.shape.ifNot("expression", apiCheck.any).optional, attribute: apiCheck.shape.ifNot("expression", apiCheck.any).optional, bound: apiCheck.shape.ifNot("expression", apiCheck.any).optional }).strict).optional, optionsTypes: apiCheck.typeOrArrayOf(apiCheck.string).optional, link: apiCheck.func.optional, controller: apiCheck.oneOfType([apiCheck.string, apiCheck.func, apiCheck.array]).optional, validation: apiCheck.shape({ show: apiCheck.oneOfType([apiCheck.bool, apiCheck.oneOf([null])]).optional, messages: apiCheck.objectOf(apiCheck.func).optional, errorExistsAndShouldBeVisible: apiCheck.bool.optional }).optional, formControl: apiCheck.object.optional, value: apiCheck.func.optional, runExpressions: apiCheck.func.optional }; var formlyFieldOptions = apiCheck.shape(fieldOptionsApiShape).strict; var typeOptionsDefaultOptions = angular.copy(fieldOptionsApiShape); typeOptionsDefaultOptions.key = apiCheck.string.optional; var formlyTypeOptions = apiCheck.shape({ name: apiCheck.string, template: apiCheck.shape.ifNot("templateUrl", apiCheck.string).optional, templateUrl: apiCheck.shape.ifNot("template", apiCheck.string).optional, controller: apiCheck.oneOfType([apiCheck.func, apiCheck.string, apiCheck.array]).optional, link: apiCheck.func.optional, defaultOptions: apiCheck.oneOfType([apiCheck.func, apiCheck.shape(typeOptionsDefaultOptions)]).optional, "extends": apiCheck.string.optional, wrapper: specifyWrapperType.optional, data: apiCheck.object.optional, validateOptions: apiCheck.func.optional, apiCheck: apiCheckProperty.optional, apiCheckInstance: apiCheckInstanceProperty.optional, apiCheckFunction: apiCheckFunctionProperty.optional, apiCheckOptions: apiCheck.object.optional, overwriteOk: apiCheck.bool.optional }).strict; angular.extend(apiCheck, { formlyTypeOptions: formlyTypeOptions, formlyFieldOptions: formlyFieldOptions, formlyExpression: formlyExpression, formlyWrapperType: formlyWrapperType }); }; /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var angular = __webpack_require__(4); module.exports = function (ngModule) { ngModule.provider("formlyUsability", ["formlyVersion", "formlyApiCheck", function (formlyVersion, formlyApiCheck) { var _this = this; var errorsAndWarningsUrlPrefix = "https://github.com/formly-js/angular-formly/blob/" + formlyVersion + "/other/ERRORS_AND_WARNINGS.md#"; angular.extend(this, { getFormlyError: getFormlyError, getFieldError: getFieldError, checkWrapper: checkWrapper, checkWrapperTemplate: checkWrapperTemplate, $get: function () { return _this; } }); function getFieldError(errorInfoSlug, message, field) { if (arguments.length < 3) { field = message; message = errorInfoSlug; errorInfoSlug = null; } return new Error(getErrorMessage(errorInfoSlug, message) + (" Field definition: " + angular.toJson(field))); } function getFormlyError(errorInfoSlug, message) { if (!message) { message = errorInfoSlug; errorInfoSlug = null; } return new Error(getErrorMessage(errorInfoSlug, message)); } function getErrorMessage(errorInfoSlug, message) { var url = ""; if (errorInfoSlug !== null) { url = "" + errorsAndWarningsUrlPrefix + "" + errorInfoSlug; } return "Formly Error: " + message + ". " + url; } function checkWrapper(wrapper) { formlyApiCheck["throw"](formlyApiCheck.formlyWrapperType, arguments, { prefix: "formlyConfig.setWrapper", urlSuffix: "setwrapper-validation-failed" }); } function checkWrapperTemplate(template, additionalInfo) { var formlyTransclude = "<formly-transclude></formly-transclude>"; if (template.indexOf(formlyTransclude) === -1) { 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))); } } }]); }; /***/ }, /* 12 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var angular = __webpack_require__(4); var utils = __webpack_require__(24); module.exports = function (ngModule) { ngModule.provider("formlyConfig", formlyConfig); formlyConfig.tests = false ? require("./formlyConfig.test")(ngModule) : null; function formlyConfig(formlyUsabilityProvider, formlyApiCheck) { var _this2 = this; var typeMap = {}; var templateWrappersMap = {}; var defaultWrapperName = "default"; var _this = this; var getError = formlyUsabilityProvider.getFormlyError; angular.extend(this, { setType: setType, getType: getType, setWrapper: setWrapper, getWrapper: getWrapper, getWrapperByType: getWrapperByType, removeWrapperByName: removeWrapperByName, removeWrappersForType: removeWrappersForType, disableWarnings: false, extras: { disableNgModelAttrsManipulator: false, ngModelAttrsManipulatorPreferBound: false }, templateManipulators: { preWrapper: [], postWrapper: [] }, $get: function () { return _this2; } }); function setType(options) { if (angular.isArray(options)) { angular.forEach(options, setType); } else if (angular.isObject(options)) { checkType(options); if (options["extends"]) { extendTypeOptions(options); } typeMap[options.name] = options; } else { throw getError("You must provide an object or array for setType. You provided: " + JSON.stringify(arguments)); } } function checkType(options) { formlyApiCheck["throw"](formlyApiCheck.formlyTypeOptions, arguments, { prefix: "formlyConfig.setType", url: "settype-validation-failed" }); if (!options.overwriteOk) { checkOverwrite(options.name, typeMap, options, "types"); } else { options.overwriteOk = undefined; } } function extendTypeOptions(options) { var extendsType = getType(options["extends"], true, options); extendTypeControllerFunction(options, extendsType); extendTypeLinkFunction(options, extendsType); extendTypeValidateOptionsFunction(options, extendsType); extendTypeDefaultOptions(options, extendsType); utils.reverseDeepMerge(options, extendsType); } function extendTypeControllerFunction(options, extendsType) { var extendsCtrl = extendsType.controller; if (!angular.isDefined(extendsCtrl)) { return; } var optionsCtrl = options.controller; if (angular.isDefined(optionsCtrl)) { options.controller = function ($scope, $controller) { $controller(extendsCtrl, { $scope: $scope }); $controller(optionsCtrl, { $scope: $scope }); }; options.controller.$inject = ["$scope", "$controller"]; } else { options.controller = extendsCtrl; } } function extendTypeLinkFunction(options, extendsType) { var extendsFn = extendsType.link; if (!angular.isDefined(extendsFn)) { return; } var optionsFn = options.link; if (angular.isDefined(optionsFn)) { options.link = function () { extendsFn.apply(undefined, arguments); optionsFn.apply(undefined, arguments); }; } else { options.link = extendsFn; } } function extendTypeValidateOptionsFunction(options, extendsType) { var extendsFn = extendsType.validateOptions; if (!angular.isDefined(extendsFn)) { return; } var optionsFn = options.validateOptions; var originalDefaultOptions = options.defaultOptions; if (angular.isDefined(optionsFn)) { options.validateOptions = function (options) { optionsFn(options); var mergedOptions = angular.copy(options); var defaultOptions = originalDefaultOptions; if (defaultOptions) { if (angular.isFunction(defaultOptions)) { defaultOptions = defaultOptions(mergedOptions); } utils.reverseDeepMerge(mergedOptions, defaultOptions); } extendsFn(mergedOptions); }; } else { options.validateOptions = extendsFn; } } function extendTypeDefaultOptions(options, extendsType) { var extendsDO = extendsType.defaultOptions; if (!angular.isDefined(extendsDO)) { return; } var optionsDO = options.defaultOptions; var optionsDOIsFn = angular.isFunction(optionsDO); var extendsDOIsFn = angular.isFunction(extendsDO); if (extendsDOIsFn) { options.defaultOptions = function defaultOptions(options) { var extendsDefaultOptions = extendsDO(options); var mergedDefaultOptions = {}; utils.reverseDeepMerge(mergedDefaultOptions, options, extendsDefaultOptions); var extenderOptionsDefaultOptions = optionsDO; if (optionsDOIsFn) { extenderOptionsDefaultOptions = extenderOptionsDefaultOptions(mergedDefaultOptions); } utils.reverseDeepMerge(extendsDefaultOptions, extenderOptionsDefaultOptions); return extendsDefaultOptions; }; } else if (optionsDOIsFn) { options.defaultOptions = function defaultOptions(options) { var newDefaultOptions = {}; utils.reverseDeepMerge(newDefaultOptions, options, extendsDO); return optionsDO(newDefaultOptions); }; } } function getType(name, throwError, errorContext) { if (!name) { return undefined; } var type = typeMap[name]; if (!type && throwError === true) { throw getError("There is no type by the name of \"" + name + "\": " + JSON.stringify(errorContext)); } else { return type; } } function setWrapper(_x, _x2) { var _again = true; _function: while (_again) { _again = false; var options = _x, name = _x2; if (angular.isArray(options)) { return options.map(function (wrapperOptions) { return setWrapper(wrapperOptions); }); } else if (angular.isObject(options)) { options.types = getOptionsTypes(options); options.name = getOptionsName(options, name); checkWrapperAPI(options); templateWrappersMap[options.name] = options; return options; } else if (angular.isString(options)) { _x = { template: options, name: name }; _again = true; continue _function; } } } function getOptionsTypes(options) { if (angular.isString(options.types)) { return [options.types]; } if (!angular.isDefined(options.types)) { return []; } else { return options.types; } } function getOptionsName(options, name) { return options.name || name || options.types.join(" ") || defaultWrapperName; } function checkWrapperAPI(options) { formlyUsabilityProvider.checkWrapper(options); if (options.template) { formlyUsabilityProvider.checkWrapperTemplate(options.template, options); } if (!options.overwriteOk) { checkOverwrite(options.name, templateWrappersMap, options, "templateWrappers"); } else { delete options.overwriteOk; } checkWrapperTypes(options); } function checkWrapperTypes(options) { var shouldThrow = !angular.isArray(options.types) || !options.types.every(angular.isString); if (shouldThrow) { throw getError("Attempted to create a template wrapper with types that is not a string or an array of strings"); } } function checkOverwrite(property, object, newValue, objectName) { if (object.hasOwnProperty(property)) { warn(["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(" ")); } } function getWrapper(name) { return templateWrappersMap[name || defaultWrapperName]; } function getWrapperByType(type) { /* jshint maxcomplexity:6 */ var wrappers = []; for (var name in templateWrappersMap) { if (templateWrappersMap.hasOwnProperty(name)) { if (templateWrappersMap[name].types && templateWrappersMap[name].types.indexOf(type) !== -1) { wrappers.push(templateWrappersMap[name]); } } } return wrappers; } function removeWrapperByName(name) { var wrapper = templateWrappersMap[name]; delete templateWrappersMap[name]; return wrapper; } function removeWrappersForType(type) { var wrappers = getWrapperByType(type); if (!wrappers) { return; } if (!angular.isArray(wrappers)) { return removeWrapperByName(wrappers.name); } else { wrappers.forEach(function (wrapper) { return removeWrapperByName(wrapper.name); }); return wrappers; } } function warn() { if (!_this.disableWarnings) { console.warn.apply(console, arguments); } } } formlyConfig.$inject = ["formlyUsabilityProvider", "formlyApiCheck"]; }; /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { ngModule.constant("formlyVersion", ("4.2.2")); }; /***/ }, /* 14 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { ngModule.constant("formlyErrorAndWarningsUrlPrefix", "https://github.com/formly-js/angular-formly/blob/" + ("4.2.2") + "/other/ERRORS_AND_WARNINGS.md#"); }; /***/ }, /* 15 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { ngModule.factory("formlyValidationMessages", function () { var formlyValidationMessages = { addTemplateOptionValueMessage: addTemplateOptionValueMessage, addStringMessage: addStringMessage, messages: {} }; return formlyValidationMessages; function addTemplateOptionValueMessage(name, prop, prefix, suffix, alternate) { formlyValidationMessages.messages[name] = templateOptionValue(prop, prefix, suffix, alternate); } function addStringMessage(name, string) { formlyValidationMessages.messages[name] = function () { return string; }; } function templateOptionValue(prop, prefix, suffix, alternate) { return function getValidationMessage(viewValue, modelValue, scope) { if (scope.options.templateOptions[prop]) { return "" + prefix + " " + scope.options.templateOptions[prop] + " " + suffix; } else { return alternate; } }; } }); }; /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var utils = __webpack_require__(24); module.exports = function (ngModule) { ngModule.factory("formlyUtil", formlyUtil); formlyUtil.tests = false ? require("./formlyUtil.test")(ngModule) : null; function formlyUtil() { return utils; } }; /***/ }, /* 17 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var _toConsumableArray = function (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); } }; module.exports = function (ngModule) { ngModule.factory("formlyWarn", ["formlyConfig", "formlyErrorAndWarningsUrlPrefix", "$log", function (formlyConfig, formlyErrorAndWarningsUrlPrefix, $log) { return function warn() { if (!formlyConfig.disableWarnings) { var args = Array.prototype.slice.call(arguments); var warnInfoSlug = args.shift(); args.unshift("Formly Warning:"); args.push("" + formlyErrorAndWarningsUrlPrefix + "" + warnInfoSlug); $log.warn.apply($log, _toConsumableArray(args)); } }; }]); }; /***/ }, /* 18 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { ngModule.directive("formlyCustomValidation", formlyCustomValidation); formlyCustomValidation.tests = false ? require("./formly-custom-validation.test")(ngModule) : null; function formlyCustomValidation(formlyUtil, $q) { return { restrict: "A", require: "ngModel", link: function link(scope, el, attrs, ctrl) { var validators = scope.$eval(attrs.formlyCustomValidation); if (!validators) { return; } checkValidators(validators); scope.options.validation.messages = scope.options.validation.messages || {}; var useNewValidatorsApi = ctrl.hasOwnProperty("$validators") && !attrs.hasOwnProperty("useParsers"); angular.forEach(validators, function (validator, name) { var message = validator.message; if (message) { scope.options.validation.messages[name] = function () { return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue); }; } validator = angular.isObject(validator) ? validator.expression : validator; var isPossiblyAsync = !angular.isString(validator); if (useNewValidatorsApi) { setupWithValidators(); } else { setupWithParsers(); } function setupWithValidators() { var validatorCollection = isPossiblyAsync ? "$asyncValidators" : "$validators"; ctrl[validatorCollection][name] = function (modelValue, viewValue) { var value = formlyUtil.formlyEval(scope, validator, modelValue, viewValue); if (isPossiblyAsync) { return isPromiseLike(value) ? value : value ? $q.when(value) : $q.reject(value); } else { return value; } }; } function setupWithParsers() { var inFlightValidator = undefined; ctrl.$parsers.unshift(function (viewValue) { var isValid = formlyUtil.formlyEval(scope, validator, ctrl.$modelValue, viewValue); if (isPromiseLike(isValid)) { ctrl.$pending = ctrl.$pending || {}; ctrl.$pending[name] = true; inFlightValidator = isValid; isValid.then(function () { if (inFlightValidator === isValid) { ctrl.$setValidity(name, true); } })["catch"](function () { if (inFlightValidator === isValid) { ctrl.$setValidity(name, false); } })["finally"](function () { if (Object.keys(ctrl.$pending).length === 1) { delete ctrl.$pending; } else { delete ctrl.$pending[name]; } }); } else { ctrl.$setValidity(name, isValid); } return viewValue; }); } }); } }; function isPromiseLike(obj) { return obj && angular.isFunction(obj.then); } function checkValidators(validators) { var allowedProperties = ["expression", "message"]; var validatorsWithExtraProps = {}; angular.forEach(validators, function (validator, name) { if (angular.isString(validator)) { return; } var extraProps = []; angular.forEach(validator, function (v, key) { if (allowedProperties.indexOf(key) === -1) { extraProps.push(key); } }); if (extraProps.length) { validatorsWithExtraProps[name] = extraProps; } }); if (Object.keys(validatorsWithExtraProps).length) { throw new Error(["Validators are only allowed to be functions or objects that have " + allowedProperties.join(", ") + ".", "You provided some extra properties: " + JSON.stringify(validatorsWithExtraProps)].join(" ")); } } } formlyCustomValidation.$inject = ["formlyUtil", "$q"]; }; /***/ }, /* 19 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var angular = __webpack_require__(4); module.exports = function (ngModule) { ngModule.directive("formlyField", formlyField); formlyField.tests = false ? require("./formly-field.test")(ngModule) : null; /** * @ngdoc directive * @name formlyField * @restrict AE */ function formlyField($http, $q, $compile, $templateCache, formlyConfig, formlyValidationMessages, formlyApiCheck, formlyUtil, formlyUsability, formlyWarn) { return { restrict: "AE", transclude: true, scope: { options: "=", model: "=", formId: "=?", index: "=?", fields: "=?", formState: "=?", form: "=?" }, controller: ["$scope", "$timeout", "$parse", "$controller", function fieldController($scope, $timeout, $parse, $controller) { var opts = $scope.options; var fieldType = opts.type && formlyConfig.getType(opts.type); simplifyLife(opts); mergeFieldOptionsWithTypeDefaults(opts, fieldType); extendOptionsWithDefaults(opts, $scope.index); checkApi(opts); // set field id to link labels and fields $scope.id = formlyUtil.getFieldId($scope.formId, opts, $scope.index); // initalization runExpressions(); setFormControl($scope, opts); addModelWatcher($scope, opts); addValidationMessages(opts); // simplify things // create $scope.to so template authors can reference to instead of $scope.options.templateOptions $scope.to = $scope.options.templateOptions; invokeControllers($scope, opts, fieldType); // function definitions function runExpressions() { $timeout(function () { // must run on next tick to make sure that the current value is correct. var field = $scope.options; var currentValue = valueGetterSetter(); angular.forEach(field.expressionProperties, function runExpression(expression, prop) { var setter = $parse(prop).assign; var promise = $q.when(formlyUtil.formlyEval($scope, expression, currentValue)); promise.then(function (value) { setter(field, value); }); }); }); } function valueGetterSetter(newVal) { if (!$scope.model || !$scope.options.key) { return; } if (angular.isDefined(newVal)) { $scope.model[$scope.options.key] = newVal; } return $scope.model[$scope.options.key]; } function simplifyLife(options) { // add a few empty objects (if they don't already exist) so you don't have to undefined check everywhere formlyUtil.reverseDeepMerge(options, { data: {}, templateOptions: {}, validation: {} }); } function mergeFieldOptionsWithTypeDefaults(options, type) { if (type) { mergeOptions(options, type.defaultOptions); } var properOrder = arrayify(options.optionsTypes).reverse(); // so the right things are overridden angular.forEach(properOrder, function (typeName) { mergeOptions(options, formlyConfig.getType(typeName, true, options).defaultOptions); }); } function mergeOptions(options, extraOptions) { if (extraOptions) { if (angular.isFunction(extraOptions)) { extraOptions = extraOptions(options); } formlyUtil.reverseDeepMerge(options, extraOptions); } } function extendOptionsWithDefaults(options, index) { angular.extend(options, { // attach the key in case the formly-field directive is used directly key: options.key || index || 0, value: valueGetterSetter, runExpressions: runExpressions }); } // initialization functions function setFormControl(scope, options) { if (options.noFormControl) { return; } scope.$watch("form[\"" + scope.id + "\"]", function (formControl) { if (formControl) { scope.fc = formControl; // shortcut for template authors scope.options.formControl = formControl; addShowMessagesWatcher(scope, options); } }); } function addModelWatcher(scope, options) { if (options.model) { scope.$watch("options.model", runExpressions, true); } } function addShowMessagesWatcher(scope, options) { scope.$watch(function () { if (typeof scope.options.validation.show === "boolean") { return scope.fc.$invalid && scope.options.validation.show; } else { return scope.fc.$invalid && scope.fc.$touched; } }, function (show) { options.validation.errorExistsAndShouldBeVisible = show; scope.showError = show; // shortcut for template authors }); } function addValidationMessages(options) { options.validation.messages = options.validation.messages || {}; angular.forEach(formlyValidationMessages.messages, function (expression, name) { if (!options.validation.messages[name]) { options.validation.messages[name] = function (viewValue, modelValue, scope) { return formlyUtil.formlyEval(scope, expression, modelValue, viewValue); }; } }); } function invokeControllers(scope) { var options = arguments[1] === undefined ? {} : arguments[1]; var type = arguments[2] === undefined ? {} : arguments[2]; angular.forEach([type.controller, options.controller], function (controller) { if (controller) { $controller(controller, { $scope: scope }); } }); } }], link: function fieldLink(scope, el) { var type = scope.options.type && formlyConfig.getType(scope.options.type); var args = arguments; var thusly = this; getFieldTemplate(scope.options).then(runManipulators(formlyConfig.templateManipulators.preWrapper)).then(transcludeInWrappers(scope.options)).then(runManipulators(formlyConfig.templateManipulators.postWrapper)).then(setElementTemplate)["catch"](function (error) { formlyWarn("there-was-a-problem-setting-the-template-for-this-field", "There was a problem setting the template for this field ", scope.options, error); }); function setElementTemplate(templateEl) { el.html(asHtml(templateEl)); $compile(el.contents())(scope); if (type && type.link) { type.link.apply(thusly, args); } if (scope.options.link) { scope.options.link.apply(thusly, args); } } function runManipulators(manipulators) { return function runManipulatorsOnTemplate(template) { var chain = $q.when(template); angular.forEach(manipulators, function (manipulator) { chain = chain.then(function (template) { return $q.when(manipulator(template, scope.options, scope)).then(function (newTemplate) { return angular.isString(newTemplate) ? newTemplate : asHtml(newTemplate); }); }); }); return chain; }; } } }; function asHtml(el) { var wrapper = angular.element("<a></a>"); return wrapper.append(el).html(); } function getFieldTemplate(options) { var type = formlyConfig.getType(options.type, true, options); var template = options.template || type && type.template; var templateUrl = options.templateUrl || type && type.templateUrl; if (!template && !templateUrl) { throw formlyUsability.getFieldError("type-type-has-no-template", "Type '" + options.type + "' has not template. On element:", options); } return getTemplate(template || templateUrl, !template); } function getTemplate(template, isUrl) { if (!isUrl) { return $q.when(template); } else { var httpOptions = { cache: $templateCache }; return $http.get(template, httpOptions).then(function (response) { return response.data; })["catch"](function (error) { formlyWarn("problem-loading-template-for-templateurl", "Problem loading template for " + template, error); }); } } function transcludeInWrappers(options) { var wrapper = getWrapperOption(options); return function transcludeTemplate(template) { if (!wrapper.length) { return $q.when(template); } wrapper.forEach(function (wrapper) { formlyUsability.checkWrapper(wrapper, options); wrapper.validateOptions && wrapper.validateOptions(options); runApiCheck(wrapper, options); }); var promises = wrapper.map(function (w) { return getTemplate(w.template || w.templateUrl, !w.template); }); return $q.all(promises).then(function (wrappersTemplates) { wrappersTemplates.forEach(function (wrapperTemplate, index) { formlyUsability.checkWrapperTemplate(wrapperTemplate, wrapper[index]); }); wrappersTemplates.reverse(); // wrapper 0 is wrapped in wrapper 1 and so on... var totalWrapper = wrappersTemplates.shift(); wrappersTemplates.forEach(function (wrapperTemplate) { totalWrapper = doTransclusion(totalWrapper, wrapperTemplate); }); return doTransclusion(totalWrapper, template); }); }; } function doTransclusion(wrapper, template) { var superWrapper = angular.element("<a></a>"); // this allows people not have to have a single root in wrappers superWrapper.append(wrapper); var transcludeEl = superWrapper.find("formly-transclude"); if (!transcludeEl.length) { //try it using our custom find function transcludeEl = formlyUtil.findByNodeName(superWrapper, "formly-transclude"); } transcludeEl.replaceWith(template); return superWrapper.html(); } function getWrapperOption(options) { var wrapper = options.wrapper; // explicit null means no wrapper if (wrapper === null) { return []; } // nothing specified means use the default wrapper for the type if (!wrapper) { // get all wrappers that specify they apply to this type wrapper = arrayify(formlyConfig.getWrapperByType(options.type)); } else { wrapper = arrayify(wrapper).map(formlyConfig.getWrapper); } // get all wrappers for that this type specified that it uses. var type = formlyConfig.getType(options.type, true, options); if (type && type.wrapper) { var typeWrappers = arrayify(type.wrapper).map(formlyConfig.getWrapper); wrapper = wrapper.concat(typeWrappers); } // add the default wrapper last var defaultWrapper = formlyConfig.getWrapper(); if (defaultWrapper) { wrapper.push(defaultWrapper); } return wrapper; } function checkApi(options) { formlyApiCheck["throw"](formlyApiCheck.formlyFieldOptions, arguments, { prefix: "formly-field directive", url: "formly-field-directive-validation-failed" }); // validate with the type var type = options.type && formlyConfig.getType(options.type); if (type) { if (type.validateOptions) { type.validateOptions(options); } runApiCheck(type, options); } } function runApiCheck(_ref, options) { var apiCheck = _ref.apiCheck; var apiCheckInstance = _ref.apiCheckInstance; var apiCheckFunction = _ref.apiCheckFunction; var apiCheckOptions = _ref.apiCheckOptions; if (!apiCheck) { return; } var instance = apiCheckInstance || formlyApiCheck; var fn = apiCheckFunction || "warn"; var shape = instance.shape(apiCheck); instance[fn](shape, [options], apiCheckOptions || { prefix: "formly-field " + name, url: formlyApiCheck.config.output.docsBaseUrl + "formly-field-type-apicheck-failed" }); } } formlyField.$inject = ["$http", "$q", "$compile", "$templateCache", "formlyConfig", "formlyValidationMessages", "formlyApiCheck", "formlyUtil", "formlyUsability", "formlyWarn"]; function arrayify(obj) { if (obj && !angular.isArray(obj)) { obj = [obj]; } else if (!obj) { obj = []; } return obj; } }; /***/ }, /* 20 */ /***/ function(module, exports, __webpack_require__) { "use strict"; var _toConsumableArray = function (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); } }; var _slice = Array.prototype.slice; var angular = __webpack_require__(4); module.exports = function (ngModule) { ngModule.directive("formlyForm", formlyForm); formlyForm.tests = false ? require("./formly-form.test")(ngModule) : null; /** * @ngdoc directive * @name formlyForm * @restrict E */ function formlyForm(formlyUsability) { var currentFormId = 1; return { restrict: "E", template: function template(el, attrs) { /* jshint -W033 */ // this because jshint is broken I guess... var rootEl = attrs.rootEl || "ng-form"; return "\n <" + rootEl + " class=\"formly\"\n name=\"form\"\n role=\"form\">\n <div formly-field\n ng-repeat=\"field in fields track by $index\"\n ng-if=\"!field.hide\"\n class=\"formly-field {{field.type ? 'formly-field-' + field.type : ''}}\"\n options=\"field\"\n model=\"field.model || model\"\n fields=\"fields\"\n form=\"form\"\n form-id=\"formId\"\n form-state=\"options.formState\"\n index=\"$index\">\n </div>\n <div ng-transclude></div>\n </" + rootEl + ">\n "; }, replace: true, transclude: true, scope: { fields: "=", model: "=", // we'll do our own warning to help with migrations form: "=?", options: "=?" }, controller: ["$scope", function controller($scope) { $scope.formId = "formly_" + currentFormId++; $scope.options = $scope.options || {}; $scope.options.formState = $scope.options.formState || {}; angular.forEach($scope.fields, attachKey); // attaches a key based on the index if a key isn't specified angular.forEach($scope.fields, setupWatchers); // setup watchers for all fields // watch the model and evaluate watch expressions that depend on it. $scope.$watch("model", function onResultUpdate(newResult) { angular.forEach($scope.fields, function (field) { /*jshint -W030 */ field.runExpressions && field.runExpressions(newResult); }); }, true); function attachKey(field, index) { field.key = field.key || index || 0; } function setupWatchers(field, index) { if (!angular.isDefined(field.watcher)) { return; } var watchers = field.watcher; if (!angular.isArray(watchers)) { watchers = [watchers]; } angular.forEach(watchers, function (watcher) { if (!angular.isDefined(watcher.listener)) { throw formlyUsability.getFieldError("all-field-watchers-must-have-a-listener", "All field watchers must have a listener", field); } var watchExpression = getWatchExpression(watcher, field, index); var watchListener = getWatchListener(watcher, field, index); var type = watcher.type || "$watch"; watcher.stopWatching = $scope[type](watchExpression, watchListener, watcher.watchDeep); }); } function getWatchExpression(watcher, field, index) { var watchExpression = watcher.expression || "model['" + field.key + "']"; if (angular.isFunction(watchExpression)) { // wrap the field's watch expression so we can call it with the field as the first arg // and the stop function as the last arg as a helper var originalExpression = watchExpression; watchExpression = function formlyWatchExpression() { var args = modifyArgs.apply(undefined, [watcher, index].concat(_slice.call(arguments))); return originalExpression.apply(undefined, _toConsumableArray(args)); }; watchExpression.displayName = "Formly Watch Expression for field for " + field.key; } return watchExpression; } function getWatchListener(watcher, field, index) { var watchListener = watcher.listener; if (angular.isFunction(watchListener)) { // wrap the field's watch listener so we can call it with the field as the first arg // and the stop function as the last arg as a helper var originalListener = watchListener; watchListener = function formlyWatchListener() { var args = modifyArgs.apply(undefined, [watcher, index].concat(_slice.call(arguments))); return originalListener.apply(undefined, _toConsumableArray(args)); }; watchListener.displayName = "Formly Watch Listener for field for " + field.key; } return watchListener; } function modifyArgs(watcher, index) { for (var _len = arguments.length, originalArgs = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { originalArgs[_key - 2] = arguments[_key]; } return [$scope.fields[index]].concat(originalArgs, [watcher.stopWatching]); } }], link: function link(scope, el, attrs) { if (attrs.hasOwnProperty("result")) { throw formlyUsability.getFormlyError("The \"result\" attribute on a formly-form is no longer valid. Use \"model\" instead"); } if (attrs.name !== "form") { // then they specified their own name throw formlyUsability.getFormlyError("The \"name\" attribute on a formly-form is no longer valid. Use \"form\" instead"); } } }; } formlyForm.$inject = ["formlyUsability"]; }; /***/ }, /* 21 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = function (ngModule) { ngModule.directive("formlyFocus", ["$timeout", "$document", function ($timeout, $document