Skip to content

Commit 766e30d

Browse files
committed
解决select为空值,选择为空的问题,同时添加initialValue替换废弃value的用法
1 parent adb6999 commit 766e30d

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/components/basic-component.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export default class BasicComponent extends React.Component {
6767
}
6868
renderFormItem(item, otherProps) {
6969
const { FormItem } = this.context;
70-
let { name, value, rules = [], ...other } = this.props;
70+
//value 有歧义已废弃,使用initialValue 替换value,同时保留value用法
71+
let { name, initialValue, value, rules = [], ...other } = this.props;
7172
const specialRules = this.getSepcialRuleByType(other.type);
7273
if (other.type === 'email' || other.type === 'url') {
7374
other.type = 'text';
@@ -80,7 +81,7 @@ export default class BasicComponent extends React.Component {
8081
<FormItem
8182
{...other}
8283
name={name}
83-
initialValue={value}
84+
initialValue={initialValue || value}
8485
rules={[
8586
...this.getDefaultRules(
8687
other.type,

src/components/form/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class Form extends React.Component {
330330
delete other.labelCol;
331331
delete other.wrapperCol;
332332
delete other.size;
333+
delete other.trigger;
333334
return <AForm {...other}>{this.props.children}</AForm>;
334335
}
335336
}
@@ -366,7 +367,7 @@ function getFormItemComponent(that) {
366367
componentDidMount() {
367368
const name = this.name;
368369
const { initialValue, rules } = this.props;
369-
if (initialValue) {
370+
if (initialValue !== undefined) {
370371
//设置初始化默认值
371372
// that.fieldsValue[name] = initialValue;
372373
//验证默认值是否合法
@@ -452,7 +453,7 @@ function getFormItemComponent(that) {
452453
onChangeOrBlurEvent = (e, shouldValidate) => {
453454
const { noFormItem, type } = this.props;
454455
let value;
455-
if (!e) {
456+
if (e === undefined) {
456457
value = undefined;
457458
} else if (e.target) {
458459
value = e.target.value;

src/components/input/array-input.jsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ export default class MultipleInput extends Input {
2222
constructor(props) {
2323
super(props);
2424
this.itemKeys = [];
25-
let { value } = this.props;
26-
if (!isArray(value)) {
27-
value = [value];
25+
// 保留原有value用法,value用法已废弃,使用initialValue代替
26+
let { value, initialValue = value } = this.props;
27+
if (!isArray(initialValue)) {
28+
initialValue = [initialValue];
2829
}
29-
value.forEach(v => {
30+
initialValue.forEach(v => {
3031
this.itemKeys.push(randomKey());
3132
});
3233
}
@@ -92,7 +93,8 @@ export default class MultipleInput extends Input {
9293
}
9394
}
9495
render() {
95-
const { value = [], ...other } = this.props;
96+
// 保留原有value用法,value用法已废弃,使用initialValue代替
97+
const { value = [], initialValue = value, ...other } = this.props;
9698
const size = this.context.size || 'default';
9799
return (
98100
<div
@@ -106,9 +108,9 @@ export default class MultipleInput extends Input {
106108
if (k !== 0) {
107109
other.label = 'null';
108110
}
109-
if (value[k] === undefined) {
111+
if (initialValue[k] === undefined) {
110112
//因为下面需要转换成字符串了
111-
value[k] = '';
113+
initialValue[k] = '';
112114
}
113115
const hideLabel = other.label === 'null' ? true : false;
114116
return (
@@ -154,7 +156,9 @@ export default class MultipleInput extends Input {
154156
arrayItemIndexs: this.itemKeys,
155157
//如果是数字转换成字符串
156158
//input表单值不存在值为数字的情况。
157-
initialValue: isArray(value) ? value[k] + '' : value + '',
159+
initialValue: isArray(initialValue)
160+
? initialValue[k] + ''
161+
: initialValue + '',
158162
}
159163
)}
160164
</Form.Item>

0 commit comments

Comments
 (0)