diff --git a/src/form/item.jsx b/src/form/item.jsx index 6532bbc332..8c9ae51163 100644 --- a/src/form/item.jsx +++ b/src/form/item.jsx @@ -327,7 +327,8 @@ export default class Item extends React.Component { const newLabel = label.replace(':', '').replace(':', ''); - const labelForErrorMessage = useLabelForErrorMessage || this.context._formLabelForErrorMessage; + const labelForErrorMessage = + useLabelForErrorMessage !== undefined ? useLabelForErrorMessage : this.context._formLabelForErrorMessage; if (labelForErrorMessage && newLabel) { return newLabel; } diff --git a/test/form/validate-spec.js b/test/form/validate-spec.js index 8ddbab254b..cd763e633d 100644 --- a/test/form/validate-spec.js +++ b/test/form/validate-spec.js @@ -356,6 +356,46 @@ describe('Submit', () => { .text() === '姓名 是必填字段' ); }); + it('the useLabelForErrorMessage of FormItem should have a higher priority', () => { + const wrapper = mount( +
+ + + +
+ ); + + wrapper + .find('input#first') + .simulate('change', { target: { value: '' } }); + wrapper.update(); + assert( + wrapper + .find('.next-form-item-help') + .first() + .text() === 'first 是必填字段' + ); + }); + it('the useLabelForErrorMessage of FormItem should have a higher priority', () => { + const wrapper = mount( +
+ + + +
+ ); + + wrapper + .find('input#first') + .simulate('change', { target: { value: '' } }); + wrapper.update(); + assert( + wrapper + .find('.next-form-item-help') + .first() + .text() === '姓名 是必填字段' + ); + }); it('validate errorMessageName', () => { const wrapper = mount(