form-item.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 69);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 3:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/utils/util");
  182. /***/ }),
  183. /***/ 4:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/mixins/emitter");
  186. /***/ }),
  187. /***/ 48:
  188. /***/ (function(module, exports) {
  189. module.exports = require("async-validator");
  190. /***/ }),
  191. /***/ 69:
  192. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  193. "use strict";
  194. __webpack_require__.r(__webpack_exports__);
  195. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/form/src/form-item.vue?vue&type=template&id=b6f3db6c&
  196. var render = function() {
  197. var _vm = this
  198. var _h = _vm.$createElement
  199. var _c = _vm._self._c || _h
  200. return _c(
  201. "div",
  202. {
  203. staticClass: "el-form-item",
  204. class: [
  205. {
  206. "el-form-item--feedback": _vm.elForm && _vm.elForm.statusIcon,
  207. "is-error": _vm.validateState === "error",
  208. "is-validating": _vm.validateState === "validating",
  209. "is-success": _vm.validateState === "success",
  210. "is-required": _vm.isRequired || _vm.required,
  211. "is-no-asterisk": _vm.elForm && _vm.elForm.hideRequiredAsterisk
  212. },
  213. _vm.sizeClass ? "el-form-item--" + _vm.sizeClass : ""
  214. ]
  215. },
  216. [
  217. _c(
  218. "label-wrap",
  219. {
  220. attrs: {
  221. "is-auto-width": _vm.labelStyle && _vm.labelStyle.width === "auto",
  222. "update-all": _vm.form.labelWidth === "auto"
  223. }
  224. },
  225. [
  226. _vm.label || _vm.$slots.label
  227. ? _c(
  228. "label",
  229. {
  230. staticClass: "el-form-item__label",
  231. style: _vm.labelStyle,
  232. attrs: { for: _vm.labelFor }
  233. },
  234. [
  235. _vm._t("label", [
  236. _vm._v(_vm._s(_vm.label + _vm.form.labelSuffix))
  237. ])
  238. ],
  239. 2
  240. )
  241. : _vm._e()
  242. ]
  243. ),
  244. _c(
  245. "div",
  246. { staticClass: "el-form-item__content", style: _vm.contentStyle },
  247. [
  248. _vm._t("default"),
  249. _c(
  250. "transition",
  251. { attrs: { name: "el-zoom-in-top" } },
  252. [
  253. _vm.validateState === "error" &&
  254. _vm.showMessage &&
  255. _vm.form.showMessage
  256. ? _vm._t(
  257. "error",
  258. [
  259. _c(
  260. "div",
  261. {
  262. staticClass: "el-form-item__error",
  263. class: {
  264. "el-form-item__error--inline":
  265. typeof _vm.inlineMessage === "boolean"
  266. ? _vm.inlineMessage
  267. : (_vm.elForm && _vm.elForm.inlineMessage) ||
  268. false
  269. }
  270. },
  271. [
  272. _vm._v(
  273. "\n " +
  274. _vm._s(_vm.validateMessage) +
  275. "\n "
  276. )
  277. ]
  278. )
  279. ],
  280. { error: _vm.validateMessage }
  281. )
  282. : _vm._e()
  283. ],
  284. 2
  285. )
  286. ],
  287. 2
  288. )
  289. ],
  290. 1
  291. )
  292. }
  293. var staticRenderFns = []
  294. render._withStripped = true
  295. // CONCATENATED MODULE: ./packages/form/src/form-item.vue?vue&type=template&id=b6f3db6c&
  296. // EXTERNAL MODULE: external "async-validator"
  297. var external_async_validator_ = __webpack_require__(48);
  298. var external_async_validator_default = /*#__PURE__*/__webpack_require__.n(external_async_validator_);
  299. // EXTERNAL MODULE: external "element-ui/lib/mixins/emitter"
  300. var emitter_ = __webpack_require__(4);
  301. var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
  302. // EXTERNAL MODULE: external "element-ui/lib/utils/merge"
  303. var merge_ = __webpack_require__(9);
  304. var merge_default = /*#__PURE__*/__webpack_require__.n(merge_);
  305. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  306. var util_ = __webpack_require__(3);
  307. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/form/src/label-wrap.vue?vue&type=script&lang=js&
  308. /* harmony default export */ var label_wrapvue_type_script_lang_js_ = ({
  309. props: {
  310. isAutoWidth: Boolean,
  311. updateAll: Boolean
  312. },
  313. inject: ['elForm', 'elFormItem'],
  314. render: function render() {
  315. var h = arguments[0];
  316. var slots = this.$slots.default;
  317. if (!slots) return null;
  318. if (this.isAutoWidth) {
  319. var autoLabelWidth = this.elForm.autoLabelWidth;
  320. var style = {};
  321. if (autoLabelWidth && autoLabelWidth !== 'auto') {
  322. var marginLeft = parseInt(autoLabelWidth, 10) - this.computedWidth;
  323. if (marginLeft) {
  324. style.marginLeft = marginLeft + 'px';
  325. }
  326. }
  327. return h(
  328. 'div',
  329. { 'class': 'el-form-item__label-wrap', style: style },
  330. [slots]
  331. );
  332. } else {
  333. return slots[0];
  334. }
  335. },
  336. methods: {
  337. getLabelWidth: function getLabelWidth() {
  338. if (this.$el && this.$el.firstElementChild) {
  339. var computedWidth = window.getComputedStyle(this.$el.firstElementChild).width;
  340. return Math.ceil(parseFloat(computedWidth));
  341. } else {
  342. return 0;
  343. }
  344. },
  345. updateLabelWidth: function updateLabelWidth() {
  346. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'update';
  347. if (this.$slots.default && this.isAutoWidth && this.$el.firstElementChild) {
  348. if (action === 'update') {
  349. this.computedWidth = this.getLabelWidth();
  350. } else if (action === 'remove') {
  351. this.elForm.deregisterLabelWidth(this.computedWidth);
  352. }
  353. }
  354. }
  355. },
  356. watch: {
  357. computedWidth: function computedWidth(val, oldVal) {
  358. if (this.updateAll) {
  359. this.elForm.registerLabelWidth(val, oldVal);
  360. this.elFormItem.updateComputedLabelWidth(val);
  361. }
  362. }
  363. },
  364. data: function data() {
  365. return {
  366. computedWidth: 0
  367. };
  368. },
  369. mounted: function mounted() {
  370. this.updateLabelWidth('update');
  371. },
  372. updated: function updated() {
  373. this.updateLabelWidth('update');
  374. },
  375. beforeDestroy: function beforeDestroy() {
  376. this.updateLabelWidth('remove');
  377. }
  378. });
  379. // CONCATENATED MODULE: ./packages/form/src/label-wrap.vue?vue&type=script&lang=js&
  380. /* harmony default export */ var src_label_wrapvue_type_script_lang_js_ = (label_wrapvue_type_script_lang_js_);
  381. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  382. var componentNormalizer = __webpack_require__(0);
  383. // CONCATENATED MODULE: ./packages/form/src/label-wrap.vue
  384. var label_wrap_render, label_wrap_staticRenderFns
  385. /* normalize component */
  386. var component = Object(componentNormalizer["a" /* default */])(
  387. src_label_wrapvue_type_script_lang_js_,
  388. label_wrap_render,
  389. label_wrap_staticRenderFns,
  390. false,
  391. null,
  392. null,
  393. null
  394. )
  395. /* hot reload */
  396. if (false) { var api; }
  397. component.options.__file = "packages/form/src/label-wrap.vue"
  398. /* harmony default export */ var label_wrap = (component.exports);
  399. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/form/src/form-item.vue?vue&type=script&lang=js&
  400. //
  401. //
  402. //
  403. //
  404. //
  405. //
  406. //
  407. //
  408. //
  409. //
  410. //
  411. //
  412. //
  413. //
  414. //
  415. //
  416. //
  417. //
  418. //
  419. //
  420. //
  421. //
  422. //
  423. //
  424. //
  425. //
  426. //
  427. //
  428. //
  429. //
  430. //
  431. //
  432. //
  433. //
  434. //
  435. //
  436. //
  437. //
  438. //
  439. //
  440. /* harmony default export */ var form_itemvue_type_script_lang_js_ = ({
  441. name: 'ElFormItem',
  442. componentName: 'ElFormItem',
  443. mixins: [emitter_default.a],
  444. provide: function provide() {
  445. return {
  446. elFormItem: this
  447. };
  448. },
  449. inject: ['elForm'],
  450. props: {
  451. label: String,
  452. labelWidth: String,
  453. prop: String,
  454. required: {
  455. type: Boolean,
  456. default: undefined
  457. },
  458. rules: [Object, Array],
  459. error: String,
  460. validateStatus: String,
  461. for: String,
  462. inlineMessage: {
  463. type: [String, Boolean],
  464. default: ''
  465. },
  466. showMessage: {
  467. type: Boolean,
  468. default: true
  469. },
  470. size: String
  471. },
  472. components: {
  473. // use this component to calculate auto width
  474. LabelWrap: label_wrap
  475. },
  476. watch: {
  477. error: {
  478. immediate: true,
  479. handler: function handler(value) {
  480. this.validateMessage = value;
  481. this.validateState = value ? 'error' : '';
  482. }
  483. },
  484. validateStatus: function validateStatus(value) {
  485. this.validateState = value;
  486. }
  487. },
  488. computed: {
  489. labelFor: function labelFor() {
  490. return this.for || this.prop;
  491. },
  492. labelStyle: function labelStyle() {
  493. var ret = {};
  494. if (this.form.labelPosition === 'top') return ret;
  495. var labelWidth = this.labelWidth || this.form.labelWidth;
  496. if (labelWidth) {
  497. ret.width = labelWidth;
  498. }
  499. return ret;
  500. },
  501. contentStyle: function contentStyle() {
  502. var ret = {};
  503. var label = this.label;
  504. if (this.form.labelPosition === 'top' || this.form.inline) return ret;
  505. if (!label && !this.labelWidth && this.isNested) return ret;
  506. var labelWidth = this.labelWidth || this.form.labelWidth;
  507. if (labelWidth === 'auto') {
  508. if (this.labelWidth === 'auto') {
  509. ret.marginLeft = this.computedLabelWidth;
  510. } else if (this.form.labelWidth === 'auto') {
  511. ret.marginLeft = this.elForm.autoLabelWidth;
  512. }
  513. } else {
  514. ret.marginLeft = labelWidth;
  515. }
  516. return ret;
  517. },
  518. form: function form() {
  519. var parent = this.$parent;
  520. var parentName = parent.$options.componentName;
  521. while (parentName !== 'ElForm') {
  522. if (parentName === 'ElFormItem') {
  523. this.isNested = true;
  524. }
  525. parent = parent.$parent;
  526. parentName = parent.$options.componentName;
  527. }
  528. return parent;
  529. },
  530. fieldValue: function fieldValue() {
  531. var model = this.form.model;
  532. if (!model || !this.prop) {
  533. return;
  534. }
  535. var path = this.prop;
  536. if (path.indexOf(':') !== -1) {
  537. path = path.replace(/:/, '.');
  538. }
  539. return Object(util_["getPropByPath"])(model, path, true).v;
  540. },
  541. isRequired: function isRequired() {
  542. var rules = this.getRules();
  543. var isRequired = false;
  544. if (rules && rules.length) {
  545. rules.every(function (rule) {
  546. if (rule.required) {
  547. isRequired = true;
  548. return false;
  549. }
  550. return true;
  551. });
  552. }
  553. return isRequired;
  554. },
  555. _formSize: function _formSize() {
  556. return this.elForm.size;
  557. },
  558. elFormItemSize: function elFormItemSize() {
  559. return this.size || this._formSize;
  560. },
  561. sizeClass: function sizeClass() {
  562. return this.elFormItemSize || (this.$ELEMENT || {}).size;
  563. }
  564. },
  565. data: function data() {
  566. return {
  567. validateState: '',
  568. validateMessage: '',
  569. validateDisabled: false,
  570. validator: {},
  571. isNested: false,
  572. computedLabelWidth: ''
  573. };
  574. },
  575. methods: {
  576. validate: function validate(trigger) {
  577. var _this = this;
  578. var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : util_["noop"];
  579. this.validateDisabled = false;
  580. var rules = this.getFilteredRule(trigger);
  581. if ((!rules || rules.length === 0) && this.required === undefined) {
  582. callback();
  583. return true;
  584. }
  585. this.validateState = 'validating';
  586. var descriptor = {};
  587. if (rules && rules.length > 0) {
  588. rules.forEach(function (rule) {
  589. delete rule.trigger;
  590. });
  591. }
  592. descriptor[this.prop] = rules;
  593. var validator = new external_async_validator_default.a(descriptor);
  594. var model = {};
  595. model[this.prop] = this.fieldValue;
  596. validator.validate(model, { firstFields: true }, function (errors, invalidFields) {
  597. _this.validateState = !errors ? 'success' : 'error';
  598. _this.validateMessage = errors ? errors[0].message : '';
  599. callback(_this.validateMessage, invalidFields);
  600. _this.elForm && _this.elForm.$emit('validate', _this.prop, !errors, _this.validateMessage || null);
  601. });
  602. },
  603. clearValidate: function clearValidate() {
  604. this.validateState = '';
  605. this.validateMessage = '';
  606. this.validateDisabled = false;
  607. },
  608. resetField: function resetField() {
  609. var _this2 = this;
  610. this.validateState = '';
  611. this.validateMessage = '';
  612. var model = this.form.model;
  613. var value = this.fieldValue;
  614. var path = this.prop;
  615. if (path.indexOf(':') !== -1) {
  616. path = path.replace(/:/, '.');
  617. }
  618. var prop = Object(util_["getPropByPath"])(model, path, true);
  619. this.validateDisabled = true;
  620. if (Array.isArray(value)) {
  621. prop.o[prop.k] = [].concat(this.initialValue);
  622. } else {
  623. prop.o[prop.k] = this.initialValue;
  624. }
  625. // reset validateDisabled after onFieldChange triggered
  626. this.$nextTick(function () {
  627. _this2.validateDisabled = false;
  628. });
  629. this.broadcast('ElTimeSelect', 'fieldReset', this.initialValue);
  630. },
  631. getRules: function getRules() {
  632. var formRules = this.form.rules;
  633. var selfRules = this.rules;
  634. var requiredRule = this.required !== undefined ? { required: !!this.required } : [];
  635. var prop = Object(util_["getPropByPath"])(formRules, this.prop || '');
  636. formRules = formRules ? prop.o[this.prop || ''] || prop.v : [];
  637. return [].concat(selfRules || formRules || []).concat(requiredRule);
  638. },
  639. getFilteredRule: function getFilteredRule(trigger) {
  640. var rules = this.getRules();
  641. return rules.filter(function (rule) {
  642. if (!rule.trigger || trigger === '') return true;
  643. if (Array.isArray(rule.trigger)) {
  644. return rule.trigger.indexOf(trigger) > -1;
  645. } else {
  646. return rule.trigger === trigger;
  647. }
  648. }).map(function (rule) {
  649. return merge_default()({}, rule);
  650. });
  651. },
  652. onFieldBlur: function onFieldBlur() {
  653. this.validate('blur');
  654. },
  655. onFieldChange: function onFieldChange() {
  656. if (this.validateDisabled) {
  657. this.validateDisabled = false;
  658. return;
  659. }
  660. this.validate('change');
  661. },
  662. updateComputedLabelWidth: function updateComputedLabelWidth(width) {
  663. this.computedLabelWidth = width ? width + 'px' : '';
  664. },
  665. addValidateEvents: function addValidateEvents() {
  666. var rules = this.getRules();
  667. if (rules.length || this.required !== undefined) {
  668. this.$on('el.form.blur', this.onFieldBlur);
  669. this.$on('el.form.change', this.onFieldChange);
  670. }
  671. },
  672. removeValidateEvents: function removeValidateEvents() {
  673. this.$off();
  674. }
  675. },
  676. mounted: function mounted() {
  677. if (this.prop) {
  678. this.dispatch('ElForm', 'el.form.addField', [this]);
  679. var initialValue = this.fieldValue;
  680. if (Array.isArray(initialValue)) {
  681. initialValue = [].concat(initialValue);
  682. }
  683. Object.defineProperty(this, 'initialValue', {
  684. value: initialValue
  685. });
  686. this.addValidateEvents();
  687. }
  688. },
  689. beforeDestroy: function beforeDestroy() {
  690. this.dispatch('ElForm', 'el.form.removeField', [this]);
  691. }
  692. });
  693. // CONCATENATED MODULE: ./packages/form/src/form-item.vue?vue&type=script&lang=js&
  694. /* harmony default export */ var src_form_itemvue_type_script_lang_js_ = (form_itemvue_type_script_lang_js_);
  695. // CONCATENATED MODULE: ./packages/form/src/form-item.vue
  696. /* normalize component */
  697. var form_item_component = Object(componentNormalizer["a" /* default */])(
  698. src_form_itemvue_type_script_lang_js_,
  699. render,
  700. staticRenderFns,
  701. false,
  702. null,
  703. null,
  704. null
  705. )
  706. /* hot reload */
  707. if (false) { var form_item_api; }
  708. form_item_component.options.__file = "packages/form/src/form-item.vue"
  709. /* harmony default export */ var form_item = (form_item_component.exports);
  710. // CONCATENATED MODULE: ./packages/form-item/index.js
  711. /* istanbul ignore next */
  712. form_item.install = function (Vue) {
  713. Vue.component(form_item.name, form_item);
  714. };
  715. /* harmony default export */ var packages_form_item = __webpack_exports__["default"] = (form_item);
  716. /***/ }),
  717. /***/ 9:
  718. /***/ (function(module, exports) {
  719. module.exports = require("element-ui/lib/utils/merge");
  720. /***/ })
  721. /******/ });