Skip to content

Commit 620774b

Browse files
committed
解决form组件value为0和空值,获取不到值的问题
1 parent 1a16c59 commit 620774b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/components/form/index.jsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,32 @@ class Form extends React.Component {
193193
componentWillMount() {
194194
this.on(
195195
'form-values',
196-
({ name, fieldValue, isArrayInput, arrayItemIndexs }) => {
196+
({
197+
name,
198+
fieldValue,
199+
formComponentType,
200+
isArrayInput,
201+
arrayItemIndexs,
202+
}) => {
197203
if (!isArrayInput) {
198-
if (fieldValue) {
204+
if (fieldValue === '') {
205+
switch (formComponentType) {
206+
case 'text':
207+
case 'input-number':
208+
case 'password':
209+
fieldValue = undefined;
210+
break;
211+
default:
212+
}
213+
}
214+
if (fieldValue !== undefined) {
199215
this.fieldsValue[name] = fieldValue;
200216
} else {
201217
delete this.fieldsValue[name];
202218
}
203219
} else {
204220
//专门处理array-input value值
205-
if (fieldValue) {
221+
if (fieldValue !== '' && fieldValue !== undefined) {
206222
this.tempFieldsValue[name] = fieldValue;
207223
} else {
208224
delete this.tempFieldsValue[name];
@@ -366,7 +382,8 @@ function getFormItemComponent(that) {
366382
}
367383
componentDidMount() {
368384
const name = this.name;
369-
const { initialValue, rules } = this.props;
385+
const { initialValue, rules, type } = this.props;
386+
this.formComponentType = type;
370387
if (initialValue !== undefined) {
371388
//设置初始化默认值
372389
// that.fieldsValue[name] = initialValue;
@@ -408,6 +425,7 @@ function getFormItemComponent(that) {
408425
}
409426
triggerFormValue(name, value) {
410427
that.trigger('form-values', {
428+
formComponentType: this.formComponentType,
411429
name,
412430
fieldValue: value,
413431
isArrayInput: this.context.isArrayInput,

0 commit comments

Comments
 (0)