Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 143ffcc

Browse files
author
Kerry
authored
Fix: server picker validates unselected option (#11020)
* add aria-label to default homeserver checkbox * test ServerPickerDialog * remove debug * strict fixes * dont validate unselected server field on ServerPickerDialog * i18n
1 parent a28f44a commit 143ffcc

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/components/views/dialogs/ServerPickerDialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,19 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
157157
private onSubmit = async (ev: SyntheticEvent): Promise<void> => {
158158
ev.preventDefault();
159159

160+
if (this.state.defaultChosen) {
161+
this.props.onFinished(this.defaultServer);
162+
}
163+
160164
const valid = await this.fieldRef.current?.validate({ allowEmpty: false });
161165

162-
if (!valid && !this.state.defaultChosen) {
166+
if (!valid) {
163167
this.fieldRef.current?.focus();
164168
this.fieldRef.current?.validate({ allowEmpty: false, focused: true });
165169
return;
166170
}
167171

168-
this.props.onFinished(this.state.defaultChosen ? this.defaultServer : this.validatedConf);
172+
this.props.onFinished(this.validatedConf);
169173
};
170174

171175
public render(): React.ReactNode {

test/components/views/dialogs/ServerPickerDialog-test.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ describe("<ServerPickerDialog />", () => {
110110

111111
fireEvent.click(screen.getByText("Continue"));
112112

113-
// serverpicker still validates the 'other homeserver' field on submit
114-
// when default is chosen
115-
// so this throws a lot of errors into the console
116-
// and is asynchronous while waiting for validation
117-
await flushPromises();
118-
119113
// closed dialog with default server
120114
expect(onFinished).toHaveBeenCalledWith(defaultServerConfig);
121115
});

0 commit comments

Comments
 (0)