|
| 1 | +import { inject } from 'vue'; |
1 | 2 | import AsyncValidator from 'async-validator';
|
2 | 3 | import cloneDeep from 'lodash/cloneDeep';
|
3 | 4 | import PropTypes from '../_util/vue-types';
|
4 | 5 | import { ColProps } from '../grid/Col';
|
5 | 6 | import {
|
6 | 7 | initDefaultProps,
|
7 |
| - getComponentFromProp, |
| 8 | + getComponent, |
8 | 9 | getOptionProps,
|
9 | 10 | getEvents,
|
10 |
| - filterEmpty, |
11 | 11 | isValidElement,
|
| 12 | + getSlot, |
12 | 13 | } from '../_util/props-util';
|
13 | 14 | import BaseMixin from '../_util/BaseMixin';
|
14 | 15 | import { ConfigConsumerProps } from '../config-provider';
|
@@ -63,15 +64,18 @@ export const FormItemProps = {
|
63 | 64 |
|
64 | 65 | export default {
|
65 | 66 | name: 'AFormModelItem',
|
66 |
| - __ANT_NEW_FORM_ITEM: true, |
67 | 67 | mixins: [BaseMixin],
|
| 68 | + inheritAttrs: false, |
| 69 | + __ANT_NEW_FORM_ITEM: true, |
68 | 70 | props: initDefaultProps(FormItemProps, {
|
69 | 71 | hasFeedback: false,
|
70 | 72 | autoLink: true,
|
71 | 73 | }),
|
72 |
| - inject: { |
73 |
| - configProvider: { default: () => ConfigConsumerProps }, |
74 |
| - FormContext: { default: () => ({}) }, |
| 74 | + setup() { |
| 75 | + return { |
| 76 | + configProvider: inject('configProvider', ConfigConsumerProps), |
| 77 | + FormContext: inject('FormContext', {}), |
| 78 | + }; |
75 | 79 | },
|
76 | 80 | data() {
|
77 | 81 | return {
|
@@ -216,43 +220,39 @@ export default {
|
216 | 220 | },
|
217 | 221 | },
|
218 | 222 | render() {
|
219 |
| - const { $slots, $scopedSlots } = this; |
220 |
| - const props = getOptionProps(this); |
221 |
| - const label = getComponentFromProp(this, 'label'); |
222 |
| - const extra = getComponentFromProp(this, 'extra'); |
223 |
| - const help = getComponentFromProp(this, 'help'); |
| 223 | + const { autoLink, ...props } = getOptionProps(this); |
| 224 | + const label = getComponent(this, 'label'); |
| 225 | + const extra = getComponent(this, 'extra'); |
| 226 | + const help = getComponent(this, 'help'); |
224 | 227 | const formProps = {
|
225 |
| - props: { |
226 |
| - ...props, |
227 |
| - label, |
228 |
| - extra, |
229 |
| - validateStatus: this.validateState, |
230 |
| - help: this.validateMessage || help, |
231 |
| - required: this.isRequired || props.required, |
232 |
| - }, |
| 228 | + ...this.$attrs, |
| 229 | + ...props, |
| 230 | + label, |
| 231 | + extra, |
| 232 | + validateStatus: this.validateState, |
| 233 | + help: this.validateMessage || help, |
| 234 | + required: this.isRequired || props.required, |
233 | 235 | };
|
234 |
| - const children = filterEmpty($scopedSlots.default ? $scopedSlots.default() : $slots.default); |
| 236 | + const children = getSlot(this); |
235 | 237 | let firstChildren = children[0];
|
236 |
| - if (this.prop && this.autoLink && isValidElement(firstChildren)) { |
| 238 | + if (this.prop && autoLink && isValidElement(firstChildren)) { |
237 | 239 | const originalEvents = getEvents(firstChildren);
|
238 |
| - const originalBlur = originalEvents.blur; |
239 |
| - const originalChange = originalEvents.change; |
| 240 | + const originalBlur = originalEvents.onBlur; |
| 241 | + const originalChange = originalEvents.onChange; |
240 | 242 | firstChildren = cloneElement(firstChildren, {
|
241 |
| - on: { |
242 |
| - blur: (...args) => { |
243 |
| - originalBlur && originalBlur(...args); |
244 |
| - this.onFieldBlur(); |
245 |
| - }, |
246 |
| - change: (...args) => { |
247 |
| - if (Array.isArray(originalChange)) { |
248 |
| - for (let i = 0, l = originalChange.length; i < l; i++) { |
249 |
| - originalChange[i](...args); |
250 |
| - } |
251 |
| - } else if (originalChange) { |
252 |
| - originalChange(...args); |
| 243 | + onBlur: (...args) => { |
| 244 | + originalBlur && originalBlur(...args); |
| 245 | + this.onFieldBlur(); |
| 246 | + }, |
| 247 | + onChange: (...args) => { |
| 248 | + if (Array.isArray(originalChange)) { |
| 249 | + for (let i = 0, l = originalChange.length; i < l; i++) { |
| 250 | + originalChange[i](...args); |
253 | 251 | }
|
254 |
| - this.onFieldChange(); |
255 |
| - }, |
| 252 | + } else if (originalChange) { |
| 253 | + originalChange(...args); |
| 254 | + } |
| 255 | + this.onFieldChange(); |
256 | 256 | },
|
257 | 257 | });
|
258 | 258 | }
|
|
0 commit comments