cy-element-ui 1.0.77 → 1.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/date-picker.js +3 -3
- package/lib/element-ui.common.js +106 -125
- package/lib/form-item.js +92 -111
- package/lib/index.js +1 -1
- package/lib/time-picker.js +3 -3
- package/lib/time-select.js +3 -3
- package/package.json +1 -1
- package/packages/date-picker/src/picker.vue +1 -1
- package/packages/form/src/form-item.vue +364 -403
- package/src/index.js +1 -1
- package/packages/form/src/label-wrap.vue +0 -81
|
@@ -1,403 +1,364 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="el-form-item" :class="[{
|
|
3
|
-
'el-form-item--feedback': elForm && elForm.statusIcon,
|
|
4
|
-
'is-error': validateState === 'error',
|
|
5
|
-
'is-validating': validateState === 'validating',
|
|
6
|
-
'is-success': validateState === 'success',
|
|
7
|
-
'is-required': isRequired || required,
|
|
8
|
-
'is-no-asterisk': elForm && elForm.hideRequiredAsterisk
|
|
9
|
-
},
|
|
10
|
-
sizeClass ? 'el-form-item--' + sizeClass : ''
|
|
11
|
-
]">
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</
|
|
18
|
-
</
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (rules && rules.length) {
|
|
242
|
-
rules.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
this.validate('change');
|
|
368
|
-
},
|
|
369
|
-
updateComputedLabelWidth(width) {
|
|
370
|
-
this.computedLabelWidth = width ? `${ width }px` : '';
|
|
371
|
-
},
|
|
372
|
-
addValidateEvents() {
|
|
373
|
-
const rules = this.getRules();
|
|
374
|
-
|
|
375
|
-
if (rules.length || this.required !== undefined) {
|
|
376
|
-
this.$on('el.form.blur', this.onFieldBlur);
|
|
377
|
-
this.$on('el.form.change', this.onFieldChange);
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
removeValidateEvents() {
|
|
381
|
-
this.$off();
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
mounted() {
|
|
385
|
-
if (this.prop) {
|
|
386
|
-
this.dispatch('ElForm', 'el.form.addField', [this]);
|
|
387
|
-
|
|
388
|
-
let initialValue = this.fieldValue;
|
|
389
|
-
if (Array.isArray(initialValue)) {
|
|
390
|
-
initialValue = [].concat(initialValue);
|
|
391
|
-
}
|
|
392
|
-
Object.defineProperty(this, 'initialValue', {
|
|
393
|
-
value: initialValue
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
this.addValidateEvents();
|
|
397
|
-
}
|
|
398
|
-
},
|
|
399
|
-
beforeDestroy() {
|
|
400
|
-
this.dispatch('ElForm', 'el.form.removeField', [this]);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="el-form-item" :class="[{
|
|
3
|
+
'el-form-item--feedback': elForm && elForm.statusIcon,
|
|
4
|
+
'is-error': validateState === 'error',
|
|
5
|
+
'is-validating': validateState === 'validating',
|
|
6
|
+
'is-success': validateState === 'success',
|
|
7
|
+
'is-required': isRequired || required,
|
|
8
|
+
'is-no-asterisk': elForm && elForm.hideRequiredAsterisk
|
|
9
|
+
},
|
|
10
|
+
sizeClass ? 'el-form-item--' + sizeClass : ''
|
|
11
|
+
]">
|
|
12
|
+
<template v-if="labelStyle && labelStyle.width === 'auto'">
|
|
13
|
+
<div class="el-form-item__label-wrap" :style="labelWrapStyle">
|
|
14
|
+
<label :for="labelFor" class="el-form-item__label" :style="labelStyle" v-if="label || $slots.label">
|
|
15
|
+
<slot name="label">{{ label + form.labelSuffix }}</slot>
|
|
16
|
+
</label>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
<template v-else>
|
|
20
|
+
<label :for="labelFor" class="el-form-item__label" :style="labelStyle" v-if="label || $slots.label">
|
|
21
|
+
<slot name="label">{{ label + form.labelSuffix }}</slot>
|
|
22
|
+
</label>
|
|
23
|
+
</template>
|
|
24
|
+
<div class="el-form-item__content" :style="contentStyle">
|
|
25
|
+
<slot></slot>
|
|
26
|
+
<transition name="el-zoom-in-top">
|
|
27
|
+
<slot
|
|
28
|
+
v-if="validateState === 'error' && showMessage && form.showMessage"
|
|
29
|
+
name="error"
|
|
30
|
+
:error="validateMessage">
|
|
31
|
+
<div
|
|
32
|
+
class="el-form-item__error"
|
|
33
|
+
:class="{
|
|
34
|
+
'el-form-item__error--inline': typeof inlineMessage === 'boolean'
|
|
35
|
+
? inlineMessage
|
|
36
|
+
: (elForm && elForm.inlineMessage || false)
|
|
37
|
+
}"
|
|
38
|
+
>
|
|
39
|
+
{{ validateMessage }}
|
|
40
|
+
</div>
|
|
41
|
+
</slot>
|
|
42
|
+
</transition>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
<script>
|
|
47
|
+
import AsyncValidator from 'async-validator';
|
|
48
|
+
import emitter from '../../../src/mixins/emitter';
|
|
49
|
+
import objectAssign from '../../../src/utils/merge';
|
|
50
|
+
import { noop, getPropByPath } from '../../../src/utils/util';
|
|
51
|
+
|
|
52
|
+
export default {
|
|
53
|
+
name: 'ElFormItem',
|
|
54
|
+
|
|
55
|
+
componentName: 'ElFormItem',
|
|
56
|
+
|
|
57
|
+
mixins: [emitter],
|
|
58
|
+
|
|
59
|
+
provide() {
|
|
60
|
+
return {
|
|
61
|
+
elFormItem: this
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
inject: ['elForm'],
|
|
66
|
+
|
|
67
|
+
props: {
|
|
68
|
+
label: String,
|
|
69
|
+
labelWidth: String,
|
|
70
|
+
prop: String,
|
|
71
|
+
required: {
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: undefined
|
|
74
|
+
},
|
|
75
|
+
rules: [Object, Array],
|
|
76
|
+
error: String,
|
|
77
|
+
validateStatus: String,
|
|
78
|
+
for: String,
|
|
79
|
+
inlineMessage: {
|
|
80
|
+
type: [String, Boolean],
|
|
81
|
+
default: ''
|
|
82
|
+
},
|
|
83
|
+
showMessage: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: true
|
|
86
|
+
},
|
|
87
|
+
size: String
|
|
88
|
+
},
|
|
89
|
+
watch: {
|
|
90
|
+
error: {
|
|
91
|
+
immediate: true,
|
|
92
|
+
handler(value) {
|
|
93
|
+
this.validateMessage = value;
|
|
94
|
+
this.validateState = value ? 'error' : '';
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
validateStatus(value) {
|
|
98
|
+
this.validateState = value;
|
|
99
|
+
},
|
|
100
|
+
rules(value) {
|
|
101
|
+
if ((!value || value.length === 0) && this.required === undefined) {
|
|
102
|
+
this.clearValidate();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
computedLabelWidth(val, oldVal) {
|
|
106
|
+
if (this.form.labelWidth === 'auto') {
|
|
107
|
+
this.elForm.registerLabelWidth(val, oldVal);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
computed: {
|
|
112
|
+
labelFor() {
|
|
113
|
+
return this.for || this.prop;
|
|
114
|
+
},
|
|
115
|
+
labelStyle() {
|
|
116
|
+
const ret = {};
|
|
117
|
+
if (this.form.labelPosition === 'top') return ret;
|
|
118
|
+
const labelWidth = this.labelWidth || this.form.labelWidth;
|
|
119
|
+
if (labelWidth) {
|
|
120
|
+
ret.width = labelWidth;
|
|
121
|
+
}
|
|
122
|
+
return ret;
|
|
123
|
+
},
|
|
124
|
+
labelWrapStyle() {
|
|
125
|
+
const style = {};
|
|
126
|
+
const autoLabelWidth = this.elForm.autoLabelWidth;
|
|
127
|
+
if (autoLabelWidth && autoLabelWidth !== 'auto') {
|
|
128
|
+
const marginLeft = parseInt(autoLabelWidth, 10) - this.computedLabelWidth;
|
|
129
|
+
if (marginLeft) {
|
|
130
|
+
style.marginLeft = marginLeft + 'px';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return style;
|
|
134
|
+
},
|
|
135
|
+
contentStyle() {
|
|
136
|
+
const ret = {};
|
|
137
|
+
const label = this.label;
|
|
138
|
+
if (this.form.labelPosition === 'top' || this.form.inline) return ret;
|
|
139
|
+
if (!label && !this.labelWidth && this.isNested) return ret;
|
|
140
|
+
const labelWidth = this.labelWidth || this.form.labelWidth;
|
|
141
|
+
if (labelWidth === 'auto') {
|
|
142
|
+
if (this.labelWidth === 'auto') {
|
|
143
|
+
ret.marginLeft = this.computedLabelWidth;
|
|
144
|
+
} else if (this.form.labelWidth === 'auto') {
|
|
145
|
+
ret.marginLeft = this.elForm.autoLabelWidth;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
ret.marginLeft = labelWidth;
|
|
149
|
+
}
|
|
150
|
+
return ret;
|
|
151
|
+
},
|
|
152
|
+
form() {
|
|
153
|
+
let parent = this.$parent;
|
|
154
|
+
let parentName = parent.$options.componentName;
|
|
155
|
+
while (parentName !== 'ElForm') {
|
|
156
|
+
if (parentName === 'ElFormItem') {
|
|
157
|
+
this.isNested = true;
|
|
158
|
+
}
|
|
159
|
+
parent = parent.$parent;
|
|
160
|
+
parentName = parent.$options.componentName;
|
|
161
|
+
}
|
|
162
|
+
return parent;
|
|
163
|
+
},
|
|
164
|
+
fieldValue() {
|
|
165
|
+
const model = this.form.model;
|
|
166
|
+
if (!model || !this.prop) { return; }
|
|
167
|
+
|
|
168
|
+
let path = this.prop;
|
|
169
|
+
if (path.indexOf(':') !== -1) {
|
|
170
|
+
path = path.replace(/:/, '.');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return getPropByPath(model, path, true).v;
|
|
174
|
+
},
|
|
175
|
+
isRequired() {
|
|
176
|
+
let rules = this.getRules();
|
|
177
|
+
let isRequired = false;
|
|
178
|
+
|
|
179
|
+
if (rules && rules.length) {
|
|
180
|
+
rules.every(rule => {
|
|
181
|
+
if (rule.required) {
|
|
182
|
+
isRequired = true;
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return isRequired;
|
|
189
|
+
},
|
|
190
|
+
_formSize() {
|
|
191
|
+
return this.elForm.size;
|
|
192
|
+
},
|
|
193
|
+
elFormItemSize() {
|
|
194
|
+
return this.size || this._formSize;
|
|
195
|
+
},
|
|
196
|
+
sizeClass() {
|
|
197
|
+
return this.elFormItemSize || (this.$ELEMENT || {}).size;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
data() {
|
|
201
|
+
return {
|
|
202
|
+
validateState: '',
|
|
203
|
+
validateMessage: '',
|
|
204
|
+
validateDisabled: false,
|
|
205
|
+
validator: {},
|
|
206
|
+
isNested: false,
|
|
207
|
+
computedLabelWidth: 0
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
methods: {
|
|
211
|
+
getLabelWidth() {
|
|
212
|
+
if (this.$el && this.$el.querySelector('.el-form-item__label')) {
|
|
213
|
+
const labelEl = this.$el.querySelector('.el-form-item__label');
|
|
214
|
+
const computedWidth = window.getComputedStyle(labelEl).width;
|
|
215
|
+
return Math.ceil(parseFloat(computedWidth));
|
|
216
|
+
} else {
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
updateLabelWidth(action) {
|
|
221
|
+
action = action || 'update';
|
|
222
|
+
if ((this.label || this.$slots.label) && this.form.labelWidth === 'auto') {
|
|
223
|
+
if (action === 'update') {
|
|
224
|
+
this.computedLabelWidth = this.getLabelWidth();
|
|
225
|
+
} else if (action === 'remove') {
|
|
226
|
+
this.elForm.deregisterLabelWidth(this.computedLabelWidth);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
validate(trigger, callback = noop) {
|
|
231
|
+
this.validateDisabled = false;
|
|
232
|
+
const rules = this.getFilteredRule(trigger);
|
|
233
|
+
if ((!rules || rules.length === 0) && this.required === undefined) {
|
|
234
|
+
callback();
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
this.validateState = 'validating';
|
|
239
|
+
|
|
240
|
+
const descriptor = {};
|
|
241
|
+
if (rules && rules.length > 0) {
|
|
242
|
+
rules.forEach(rule => {
|
|
243
|
+
delete rule.trigger;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
descriptor[this.prop] = rules;
|
|
247
|
+
|
|
248
|
+
const validator = new AsyncValidator(descriptor);
|
|
249
|
+
const model = {};
|
|
250
|
+
|
|
251
|
+
model[this.prop] = this.fieldValue;
|
|
252
|
+
|
|
253
|
+
validator.validate(model, { firstFields: true }, (errors, invalidFields) => {
|
|
254
|
+
this.validateState = !errors ? 'success' : 'error';
|
|
255
|
+
this.validateMessage = errors ? errors[0].message : '';
|
|
256
|
+
|
|
257
|
+
callback(this.validateMessage, invalidFields);
|
|
258
|
+
this.elForm && this.elForm.$emit('validate', this.prop, !errors, this.validateMessage || null);
|
|
259
|
+
});
|
|
260
|
+
},
|
|
261
|
+
clearValidate() {
|
|
262
|
+
this.validateState = '';
|
|
263
|
+
this.validateMessage = '';
|
|
264
|
+
this.validateDisabled = false;
|
|
265
|
+
},
|
|
266
|
+
resetField() {
|
|
267
|
+
this.validateState = '';
|
|
268
|
+
this.validateMessage = '';
|
|
269
|
+
|
|
270
|
+
let model = this.form.model;
|
|
271
|
+
let value = this.fieldValue;
|
|
272
|
+
let path = this.prop;
|
|
273
|
+
if (path.indexOf(':') !== -1) {
|
|
274
|
+
path = path.replace(/:/, '.');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let prop = getPropByPath(model, path, true);
|
|
278
|
+
|
|
279
|
+
this.validateDisabled = true;
|
|
280
|
+
if (Array.isArray(value)) {
|
|
281
|
+
prop.o[prop.k] = [].concat(this.initialValue);
|
|
282
|
+
} else {
|
|
283
|
+
prop.o[prop.k] = this.initialValue;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
this.$nextTick(() => {
|
|
287
|
+
this.validateDisabled = false;
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
this.broadcast('ElTimeSelect', 'fieldReset', this.initialValue);
|
|
291
|
+
},
|
|
292
|
+
getRules() {
|
|
293
|
+
let formRules = this.form.rules;
|
|
294
|
+
const selfRules = this.rules;
|
|
295
|
+
const requiredRule = this.required !== undefined ? { required: !!this.required } : [];
|
|
296
|
+
|
|
297
|
+
const prop = getPropByPath(formRules, this.prop || '');
|
|
298
|
+
formRules = formRules ? (prop.o[this.prop || ''] || prop.v) : [];
|
|
299
|
+
|
|
300
|
+
return [].concat(selfRules || formRules || []).concat(requiredRule);
|
|
301
|
+
},
|
|
302
|
+
getFilteredRule(trigger) {
|
|
303
|
+
const rules = this.getRules();
|
|
304
|
+
|
|
305
|
+
return rules.filter(rule => {
|
|
306
|
+
if (!rule.trigger || trigger === '') return true;
|
|
307
|
+
if (Array.isArray(rule.trigger)) {
|
|
308
|
+
return rule.trigger.indexOf(trigger) > -1;
|
|
309
|
+
} else {
|
|
310
|
+
return rule.trigger === trigger;
|
|
311
|
+
}
|
|
312
|
+
}).map(rule => objectAssign({}, rule));
|
|
313
|
+
},
|
|
314
|
+
onFieldBlur() {
|
|
315
|
+
this.validate('blur');
|
|
316
|
+
},
|
|
317
|
+
onFieldChange() {
|
|
318
|
+
if (this.validateDisabled) {
|
|
319
|
+
this.validateDisabled = false;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
this.validate('change');
|
|
324
|
+
},
|
|
325
|
+
updateComputedLabelWidth(width) {
|
|
326
|
+
this.computedLabelWidth = width ? `${ width }px` : '';
|
|
327
|
+
},
|
|
328
|
+
addValidateEvents() {
|
|
329
|
+
const rules = this.getRules();
|
|
330
|
+
|
|
331
|
+
if (rules.length || this.required !== undefined) {
|
|
332
|
+
this.$on('el.form.blur', this.onFieldBlur);
|
|
333
|
+
this.$on('el.form.change', this.onFieldChange);
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
removeValidateEvents() {
|
|
337
|
+
this.$off();
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
mounted() {
|
|
341
|
+
this.updateLabelWidth('update');
|
|
342
|
+
if (this.prop) {
|
|
343
|
+
this.dispatch('ElForm', 'el.form.addField', [this]);
|
|
344
|
+
|
|
345
|
+
let initialValue = this.fieldValue;
|
|
346
|
+
if (Array.isArray(initialValue)) {
|
|
347
|
+
initialValue = [].concat(initialValue);
|
|
348
|
+
}
|
|
349
|
+
Object.defineProperty(this, 'initialValue', {
|
|
350
|
+
value: initialValue
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
this.addValidateEvents();
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
updated() {
|
|
357
|
+
this.updateLabelWidth('update');
|
|
358
|
+
},
|
|
359
|
+
beforeDestroy() {
|
|
360
|
+
this.updateLabelWidth('remove');
|
|
361
|
+
this.dispatch('ElForm', 'el.form.removeField', [this]);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
</script>
|