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
This commit is contained in:
parent
a28f44a075
commit
143ffccb0a
2 changed files with 6 additions and 8 deletions
|
@ -157,15 +157,19 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
|
||||||
private onSubmit = async (ev: SyntheticEvent): Promise<void> => {
|
private onSubmit = async (ev: SyntheticEvent): Promise<void> => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
|
if (this.state.defaultChosen) {
|
||||||
|
this.props.onFinished(this.defaultServer);
|
||||||
|
}
|
||||||
|
|
||||||
const valid = await this.fieldRef.current?.validate({ allowEmpty: false });
|
const valid = await this.fieldRef.current?.validate({ allowEmpty: false });
|
||||||
|
|
||||||
if (!valid && !this.state.defaultChosen) {
|
if (!valid) {
|
||||||
this.fieldRef.current?.focus();
|
this.fieldRef.current?.focus();
|
||||||
this.fieldRef.current?.validate({ allowEmpty: false, focused: true });
|
this.fieldRef.current?.validate({ allowEmpty: false, focused: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onFinished(this.state.defaultChosen ? this.defaultServer : this.validatedConf);
|
this.props.onFinished(this.validatedConf);
|
||||||
};
|
};
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
|
|
|
@ -110,12 +110,6 @@ describe("<ServerPickerDialog />", () => {
|
||||||
|
|
||||||
fireEvent.click(screen.getByText("Continue"));
|
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
|
// closed dialog with default server
|
||||||
expect(onFinished).toHaveBeenCalledWith(defaultServerConfig);
|
expect(onFinished).toHaveBeenCalledWith(defaultServerConfig);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue