form-item.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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. rules: function rules(value) {
  488. if ((!value || value.length === 0) && this.required === undefined) {
  489. this.clearValidate();
  490. }
  491. }
  492. },
  493. computed: {
  494. labelFor: function labelFor() {
  495. return this.for || this.prop;
  496. },
  497. labelStyle: function labelStyle() {
  498. var ret = {};
  499. if (this.form.labelPosition === 'top') return ret;
  500. var labelWidth = this.labelWidth || this.form.labelWidth;
  501. if (labelWidth) {
  502. ret.width = labelWidth;
  503. }
  504. return ret;
  505. },
  506. contentStyle: function contentStyle() {
  507. var ret = {};
  508. var label = this.label;
  509. if (this.form.labelPosition === 'top' || this.form.inline) return ret;
  510. if (!label && !this.labelWidth && this.isNested) return ret;
  511. var labelWidth = this.labelWidth || this.form.labelWidth;
  512. if (labelWidth === 'auto') {
  513. if (this.labelWidth === 'auto') {
  514. ret.marginLeft = this.computedLabelWidth;
  515. } else if (this.form.labelWidth === 'auto') {
  516. ret.marginLeft = this.elForm.autoLabelWidth;
  517. }
  518. } else {
  519. ret.marginLeft = labelWidth;
  520. }
  521. return ret;
  522. },
  523. form: function form() {
  524. var parent = this.$parent;
  525. var parentName = parent.$options.componentName;
  526. while (parentName !== 'ElForm') {
  527. if (parentName === 'ElFormItem') {
  528. this.isNested = true;
  529. }
  530. parent = parent.$parent;
  531. parentName = parent.$options.componentName;
  532. }
  533. return parent;
  534. },
  535. fieldValue: function fieldValue() {
  536. var model = this.form.model;
  537. if (!model || !this.prop) {
  538. return;
  539. }
  540. var path = this.prop;
  541. if (path.indexOf(':') !== -1) {
  542. path = path.replace(/:/, '.');
  543. }
  544. return Object(util_["getPropByPath"])(model, path, true).v;
  545. },
  546. isRequired: function isRequired() {
  547. var rules = this.getRules();
  548. var isRequired = false;
  549. if (rules && rules.length) {
  550. rules.every(function (rule) {
  551. if (rule.required) {
  552. isRequired = true;
  553. return false;
  554. }
  555. return true;
  556. });
  557. }
  558. return isRequired;
  559. },
  560. _formSize: function _formSize() {
  561. return this.elForm.size;
  562. },
  563. elFormItemSize: function elFormItemSize() {
  564. return this.size || this._formSize;
  565. },
  566. sizeClass: function sizeClass() {
  567. return this.elFormItemSize || (this.$ELEMENT || {}).size;
  568. }
  569. },
  570. data: function data() {
  571. return {
  572. validateState: '',
  573. validateMessage: '',
  574. validateDisabled: false,
  575. validator: {},
  576. isNested: false,
  577. computedLabelWidth: ''
  578. };
  579. },
  580. methods: {
  581. validate: function validate(trigger) {
  582. var _this = this;
  583. var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : util_["noop"];
  584. this.validateDisabled = false;
  585. var rules = this.getFilteredRule(trigger);
  586. if ((!rules || rules.length === 0) && this.required === undefined) {
  587. callback();
  588. return true;
  589. }
  590. this.validateState = 'validating';
  591. var descriptor = {};
  592. if (rules && rules.length > 0) {
  593. rules.forEach(function (rule) {
  594. delete rule.trigger;
  595. });
  596. }
  597. descriptor[this.prop] = rules;
  598. var validator = new external_async_validator_default.a(descriptor);
  599. var model = {};
  600. model[this.prop] = this.fieldValue;
  601. validator.validate(model, { firstFields: true }, function (errors, invalidFields) {
  602. _this.validateState = !errors ? 'success' : 'error';
  603. _this.validateMessage = errors ? errors[0].message : '';
  604. callback(_this.validateMessage, invalidFields);
  605. _this.elForm && _this.elForm.$emit('validate', _this.prop, !errors, _this.validateMessage || null);
  606. });
  607. },
  608. clearValidate: function clearValidate() {
  609. this.validateState = '';
  610. this.validateMessage = '';
  611. this.validateDisabled = false;
  612. },
  613. resetField: function resetField() {
  614. var _this2 = this;
  615. this.validateState = '';
  616. this.validateMessage = '';
  617. var model = this.form.model;
  618. var value = this.fieldValue;
  619. var path = this.prop;
  620. if (path.indexOf(':') !== -1) {
  621. path = path.replace(/:/, '.');
  622. }
  623. var prop = Object(util_["getPropByPath"])(model, path, true);
  624. this.validateDisabled = true;
  625. if (Array.isArray(value)) {
  626. prop.o[prop.k] = [].concat(this.initialValue);
  627. } else {
  628. prop.o[prop.k] = this.initialValue;
  629. }
  630. // reset validateDisabled after onFieldChange triggered
  631. this.$nextTick(function () {
  632. _this2.validateDisabled = false;
  633. });
  634. this.broadcast('ElTimeSelect', 'fieldReset', this.initialValue);
  635. },
  636. getRules: function getRules() {
  637. var formRules = this.form.rules;
  638. var selfRules = this.rules;
  639. var requiredRule = this.required !== undefined ? { required: !!this.required } : [];
  640. var prop = Object(util_["getPropByPath"])(formRules, this.prop || '');
  641. formRules = formRules ? prop.o[this.prop || ''] || prop.v : [];
  642. return [].concat(selfRules || formRules || []).concat(requiredRule);
  643. },
  644. getFilteredRule: function getFilteredRule(trigger) {
  645. var rules = this.getRules();
  646. return rules.filter(function (rule) {
  647. if (!rule.trigger || trigger === '') return true;
  648. if (Array.isArray(rule.trigger)) {
  649. return rule.trigger.indexOf(trigger) > -1;
  650. } else {
  651. return rule.trigger === trigger;
  652. }
  653. }).map(function (rule) {
  654. return merge_default()({}, rule);
  655. });
  656. },
  657. onFieldBlur: function onFieldBlur() {
  658. this.validate('blur');
  659. },
  660. onFieldChange: function onFieldChange() {
  661. if (this.validateDisabled) {
  662. this.validateDisabled = false;
  663. return;
  664. }
  665. this.validate('change');
  666. },
  667. updateComputedLabelWidth: function updateComputedLabelWidth(width) {
  668. this.computedLabelWidth = width ? width + 'px' : '';
  669. },
  670. addValidateEvents: function addValidateEvents() {
  671. var rules = this.getRules();
  672. if (rules.length || this.required !== undefined) {
  673. this.$on('el.form.blur', this.onFieldBlur);
  674. this.$on('el.form.change', this.onFieldChange);
  675. }
  676. },
  677. removeValidateEvents: function removeValidateEvents() {
  678. this.$off();
  679. }
  680. },
  681. mounted: function mounted() {
  682. if (this.prop) {
  683. this.dispatch('ElForm', 'el.form.addField', [this]);
  684. var initialValue = this.fieldValue;
  685. if (Array.isArray(initialValue)) {
  686. initialValue = [].concat(initialValue);
  687. }
  688. Object.defineProperty(this, 'initialValue', {
  689. value: initialValue
  690. });
  691. this.addValidateEvents();
  692. }
  693. },
  694. beforeDestroy: function beforeDestroy() {
  695. this.dispatch('ElForm', 'el.form.removeField', [this]);
  696. }
  697. });
  698. // CONCATENATED MODULE: ./packages/form/src/form-item.vue?vue&type=script&lang=js&
  699. /* harmony default export */ var src_form_itemvue_type_script_lang_js_ = (form_itemvue_type_script_lang_js_);
  700. // CONCATENATED MODULE: ./packages/form/src/form-item.vue
  701. /* normalize component */
  702. var form_item_component = Object(componentNormalizer["a" /* default */])(
  703. src_form_itemvue_type_script_lang_js_,
  704. render,
  705. staticRenderFns,
  706. false,
  707. null,
  708. null,
  709. null
  710. )
  711. /* hot reload */
  712. if (false) { var form_item_api; }
  713. form_item_component.options.__file = "packages/form/src/form-item.vue"
  714. /* harmony default export */ var form_item = (form_item_component.exports);
  715. // CONCATENATED MODULE: ./packages/form-item/index.js
  716. /* istanbul ignore next */
  717. form_item.install = function (Vue) {
  718. Vue.component(form_item.name, form_item);
  719. };
  720. /* harmony default export */ var packages_form_item = __webpack_exports__["default"] = (form_item);
  721. /***/ }),
  722. /***/ 9:
  723. /***/ (function(module, exports) {
  724. module.exports = require("element-ui/lib/utils/merge");
  725. /***/ })
  726. /******/ });