form-item.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 260);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 1:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/mixins/emitter");
  166. /***/ }),
  167. /***/ 260:
  168. /***/ (function(module, exports, __webpack_require__) {
  169. module.exports = __webpack_require__(261);
  170. /***/ }),
  171. /***/ 261:
  172. /***/ (function(module, exports, __webpack_require__) {
  173. "use strict";
  174. exports.__esModule = true;
  175. var _formItem = __webpack_require__(262);
  176. var _formItem2 = _interopRequireDefault(_formItem);
  177. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  178. /* istanbul ignore next */
  179. _formItem2.default.install = function (Vue) {
  180. Vue.component(_formItem2.default.name, _formItem2.default);
  181. };
  182. exports.default = _formItem2.default;
  183. /***/ }),
  184. /***/ 262:
  185. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  186. "use strict";
  187. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  188. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_form_item_vue__ = __webpack_require__(263);
  189. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_form_item_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_form_item_vue__);
  190. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_f06fe54a_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_form_item_vue__ = __webpack_require__(265);
  191. var normalizeComponent = __webpack_require__(0)
  192. /* script */
  193. /* template */
  194. /* template functional */
  195. var __vue_template_functional__ = false
  196. /* styles */
  197. var __vue_styles__ = null
  198. /* scopeId */
  199. var __vue_scopeId__ = null
  200. /* moduleIdentifier (server only) */
  201. var __vue_module_identifier__ = null
  202. var Component = normalizeComponent(
  203. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_form_item_vue___default.a,
  204. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_f06fe54a_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_form_item_vue__["a" /* default */],
  205. __vue_template_functional__,
  206. __vue_styles__,
  207. __vue_scopeId__,
  208. __vue_module_identifier__
  209. )
  210. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  211. /***/ }),
  212. /***/ 263:
  213. /***/ (function(module, exports, __webpack_require__) {
  214. "use strict";
  215. exports.__esModule = true;
  216. var _asyncValidator = __webpack_require__(264);
  217. var _asyncValidator2 = _interopRequireDefault(_asyncValidator);
  218. var _emitter = __webpack_require__(1);
  219. var _emitter2 = _interopRequireDefault(_emitter);
  220. var _merge = __webpack_require__(9);
  221. var _merge2 = _interopRequireDefault(_merge);
  222. var _util = __webpack_require__(3);
  223. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  224. //
  225. //
  226. //
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. exports.default = {
  256. name: 'ElFormItem',
  257. componentName: 'ElFormItem',
  258. mixins: [_emitter2.default],
  259. provide: function provide() {
  260. return {
  261. elFormItem: this
  262. };
  263. },
  264. inject: ['elForm'],
  265. props: {
  266. label: String,
  267. labelWidth: String,
  268. prop: String,
  269. required: {
  270. type: Boolean,
  271. default: undefined
  272. },
  273. rules: [Object, Array],
  274. error: String,
  275. validateStatus: String,
  276. for: String,
  277. inlineMessage: {
  278. type: [String, Boolean],
  279. default: ''
  280. },
  281. showMessage: {
  282. type: Boolean,
  283. default: true
  284. },
  285. size: String
  286. },
  287. watch: {
  288. error: function error(value) {
  289. this.validateMessage = value;
  290. this.validateState = value ? 'error' : '';
  291. },
  292. validateStatus: function validateStatus(value) {
  293. this.validateState = value;
  294. }
  295. },
  296. computed: {
  297. labelFor: function labelFor() {
  298. return this.for || this.prop;
  299. },
  300. labelStyle: function labelStyle() {
  301. var ret = {};
  302. if (this.form.labelPosition === 'top') return ret;
  303. var labelWidth = this.labelWidth || this.form.labelWidth;
  304. if (labelWidth) {
  305. ret.width = labelWidth;
  306. }
  307. return ret;
  308. },
  309. contentStyle: function contentStyle() {
  310. var ret = {};
  311. var label = this.label;
  312. if (this.form.labelPosition === 'top' || this.form.inline) return ret;
  313. if (!label && !this.labelWidth && this.isNested) return ret;
  314. var labelWidth = this.labelWidth || this.form.labelWidth;
  315. if (labelWidth) {
  316. ret.marginLeft = labelWidth;
  317. }
  318. return ret;
  319. },
  320. form: function form() {
  321. var parent = this.$parent;
  322. var parentName = parent.$options.componentName;
  323. while (parentName !== 'ElForm') {
  324. if (parentName === 'ElFormItem') {
  325. this.isNested = true;
  326. }
  327. parent = parent.$parent;
  328. parentName = parent.$options.componentName;
  329. }
  330. return parent;
  331. },
  332. fieldValue: {
  333. cache: false,
  334. get: function get() {
  335. var model = this.form.model;
  336. if (!model || !this.prop) {
  337. return;
  338. }
  339. var path = this.prop;
  340. if (path.indexOf(':') !== -1) {
  341. path = path.replace(/:/, '.');
  342. }
  343. return (0, _util.getPropByPath)(model, path, true).v;
  344. }
  345. },
  346. isRequired: function isRequired() {
  347. var rules = this.getRules();
  348. var isRequired = false;
  349. if (rules && rules.length) {
  350. rules.every(function (rule) {
  351. if (rule.required) {
  352. isRequired = true;
  353. return false;
  354. }
  355. return true;
  356. });
  357. }
  358. return isRequired;
  359. },
  360. _formSize: function _formSize() {
  361. return this.elForm.size;
  362. },
  363. elFormItemSize: function elFormItemSize() {
  364. return this.size || this._formSize;
  365. },
  366. sizeClass: function sizeClass() {
  367. return (this.$ELEMENT || {}).size || this.elFormItemSize;
  368. }
  369. },
  370. data: function data() {
  371. return {
  372. validateState: '',
  373. validateMessage: '',
  374. validateDisabled: false,
  375. validator: {},
  376. isNested: false
  377. };
  378. },
  379. methods: {
  380. validate: function validate(trigger) {
  381. var _this = this;
  382. var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _util.noop;
  383. this.validateDisabled = false;
  384. var rules = this.getFilteredRule(trigger);
  385. if ((!rules || rules.length === 0) && this.required === undefined) {
  386. callback();
  387. return true;
  388. }
  389. this.validateState = 'validating';
  390. var descriptor = {};
  391. if (rules && rules.length > 0) {
  392. rules.forEach(function (rule) {
  393. delete rule.trigger;
  394. });
  395. }
  396. descriptor[this.prop] = rules;
  397. var validator = new _asyncValidator2.default(descriptor);
  398. var model = {};
  399. model[this.prop] = this.fieldValue;
  400. validator.validate(model, { firstFields: true }, function (errors, fields) {
  401. _this.validateState = !errors ? 'success' : 'error';
  402. _this.validateMessage = errors ? errors[0].message : '';
  403. callback(_this.validateMessage);
  404. });
  405. },
  406. clearValidate: function clearValidate() {
  407. this.validateState = '';
  408. this.validateMessage = '';
  409. this.validateDisabled = false;
  410. },
  411. resetField: function resetField() {
  412. this.validateState = '';
  413. this.validateMessage = '';
  414. var model = this.form.model;
  415. var value = this.fieldValue;
  416. var path = this.prop;
  417. if (path.indexOf(':') !== -1) {
  418. path = path.replace(/:/, '.');
  419. }
  420. var prop = (0, _util.getPropByPath)(model, path, true);
  421. if (Array.isArray(value)) {
  422. this.validateDisabled = true;
  423. prop.o[prop.k] = [].concat(this.initialValue);
  424. } else {
  425. this.validateDisabled = true;
  426. prop.o[prop.k] = this.initialValue;
  427. }
  428. },
  429. getRules: function getRules() {
  430. var formRules = this.form.rules;
  431. var selfRules = this.rules;
  432. var requiredRule = this.required !== undefined ? { required: !!this.required } : [];
  433. formRules = formRules ? (0, _util.getPropByPath)(formRules, this.prop || '').v : [];
  434. return [].concat(selfRules || formRules || []).concat(requiredRule);
  435. },
  436. getFilteredRule: function getFilteredRule(trigger) {
  437. var rules = this.getRules();
  438. return rules.filter(function (rule) {
  439. return !rule.trigger || rule.trigger.indexOf(trigger) !== -1;
  440. }).map(function (rule) {
  441. return (0, _merge2.default)({}, rule);
  442. });
  443. },
  444. onFieldBlur: function onFieldBlur() {
  445. this.validate('blur');
  446. },
  447. onFieldChange: function onFieldChange() {
  448. if (this.validateDisabled) {
  449. this.validateDisabled = false;
  450. return;
  451. }
  452. this.validate('change');
  453. }
  454. },
  455. mounted: function mounted() {
  456. if (this.prop) {
  457. this.dispatch('ElForm', 'el.form.addField', [this]);
  458. var initialValue = this.fieldValue;
  459. if (Array.isArray(initialValue)) {
  460. initialValue = [].concat(initialValue);
  461. }
  462. Object.defineProperty(this, 'initialValue', {
  463. value: initialValue
  464. });
  465. var rules = this.getRules();
  466. if (rules.length || this.required !== undefined) {
  467. this.$on('el.form.blur', this.onFieldBlur);
  468. this.$on('el.form.change', this.onFieldChange);
  469. }
  470. }
  471. },
  472. beforeDestroy: function beforeDestroy() {
  473. this.dispatch('ElForm', 'el.form.removeField', [this]);
  474. }
  475. };
  476. /***/ }),
  477. /***/ 264:
  478. /***/ (function(module, exports) {
  479. module.exports = require("async-validator");
  480. /***/ }),
  481. /***/ 265:
  482. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  483. "use strict";
  484. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-form-item",class:[{
  485. 'el-form-item--feedback': _vm.elForm && _vm.elForm.statusIcon,
  486. 'is-error': _vm.validateState === 'error',
  487. 'is-validating': _vm.validateState === 'validating',
  488. 'is-success': _vm.validateState === 'success',
  489. 'is-required': _vm.isRequired || _vm.required
  490. },
  491. _vm.sizeClass ? 'el-form-item--' + _vm.sizeClass : ''
  492. ]},[(_vm.label || _vm.$slots.label)?_c('label',{staticClass:"el-form-item__label",style:(_vm.labelStyle),attrs:{"for":_vm.labelFor}},[_vm._t("label",[_vm._v(_vm._s(_vm.label + _vm.form.labelSuffix))])],2):_vm._e(),_c('div',{staticClass:"el-form-item__content",style:(_vm.contentStyle)},[_vm._t("default"),_c('transition',{attrs:{"name":"el-zoom-in-top"}},[(_vm.validateState === 'error' && _vm.showMessage && _vm.form.showMessage)?_c('div',{staticClass:"el-form-item__error",class:{
  493. 'el-form-item__error--inline': typeof _vm.inlineMessage === 'boolean'
  494. ? _vm.inlineMessage
  495. : (_vm.elForm && _vm.elForm.inlineMessage || false)
  496. }},[_vm._v("\n "+_vm._s(_vm.validateMessage)+"\n ")]):_vm._e()])],2)])}
  497. var staticRenderFns = []
  498. var esExports = { render: render, staticRenderFns: staticRenderFns }
  499. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  500. /***/ }),
  501. /***/ 3:
  502. /***/ (function(module, exports) {
  503. module.exports = require("element-ui/lib/utils/util");
  504. /***/ }),
  505. /***/ 9:
  506. /***/ (function(module, exports) {
  507. module.exports = require("element-ui/lib/utils/merge");
  508. /***/ })
  509. /******/ });