From d62ecd6b4f366cbcd270ea45b70ab960903313ee Mon Sep 17 00:00:00 2001 From: Si Yang Date: Sat, 3 Sep 2022 00:53:16 +0800 Subject: [PATCH 1/2] fix(FormItem): priority of properties The useLabelForErrorMessage of FormItem should have a higher priority. --- src/form/item.jsx | 2 +- test/form/validate-spec.js | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/form/item.jsx b/src/form/item.jsx index 6532bbc332..62a9c8af41 100644 --- a/src/form/item.jsx +++ b/src/form/item.jsx @@ -327,7 +327,7 @@ export default class Item extends React.Component { const newLabel = label.replace(':', '').replace(':', ''); - const labelForErrorMessage = useLabelForErrorMessage || this.context._formLabelForErrorMessage; + const labelForErrorMessage = 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(
From 141b5b77003fcc9b24e64c01cfece3da735ebf84 Mon Sep 17 00:00:00 2001 From: Si Yang Date: Mon, 5 Sep 2022 08:49:08 +0800 Subject: [PATCH 2/2] fix(FormItem): build failed: SyntaxError --- src/form/item.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/form/item.jsx b/src/form/item.jsx index 62a9c8af41..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; }