Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Form.Item): priority of properties #4088

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/form/item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
40 changes: 40 additions & 0 deletions test/form/validate-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,46 @@ describe('Submit', () => {
.text() === '姓名 是必填字段'
);
});
it('the useLabelForErrorMessage of FormItem should have a higher priority', () => {
const wrapper = mount(
<Form useLabelForErrorMessage>
<FormItem useLabelForErrorMessage={false} required label="姓名" >
<Input name="first" />
</FormItem>
</Form>
);

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(
<Form useLabelForErrorMessage={false}>
<FormItem useLabelForErrorMessage required label="姓名" >
<Input name="first" />
</FormItem>
</Form>
);

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(
<Form useLabelForErrorMessage>
Expand Down