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

Fix: server picker validates unselected option #11020

Merged
merged 7 commits into from
Jun 1, 2023
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
8 changes: 6 additions & 2 deletions src/components/views/dialogs/ServerPickerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,19 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
private onSubmit = async (ev: SyntheticEvent): Promise<void> => {
ev.preventDefault();

if (this.state.defaultChosen) {
this.props.onFinished(this.defaultServer);
}

const valid = await this.fieldRef.current?.validate({ allowEmpty: false });

if (!valid && !this.state.defaultChosen) {
if (!valid) {
this.fieldRef.current?.focus();
this.fieldRef.current?.validate({ allowEmpty: false, focused: true });
return;
}

this.props.onFinished(this.state.defaultChosen ? this.defaultServer : this.validatedConf);
this.props.onFinished(this.validatedConf);
};

public render(): React.ReactNode {
Expand Down
6 changes: 0 additions & 6 deletions test/components/views/dialogs/ServerPickerDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ describe("<ServerPickerDialog />", () => {

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

// serverpicker still validates the 'other homeserver' field on submit
// when default is chosen
// so this throws a lot of errors into the console
// and is asynchronous while waiting for validation
await flushPromises();

// closed dialog with default server
expect(onFinished).toHaveBeenCalledWith(defaultServerConfig);
});
Expand Down