Prevent default form action (#3172)

This commit is contained in:
Jason Hu 2019-05-08 07:48:33 -07:00 committed by Paulus Schoutsen
parent cd5e274ffa
commit 89a35a0062
2 changed files with 6 additions and 4 deletions

View File

@ -130,7 +130,7 @@ class OnboardingCreateUser extends LitElement {
);
this.addEventListener("keypress", (ev) => {
if (ev.keyCode === 13) {
this._submitForm();
this._submitForm(ev);
}
});
}
@ -152,7 +152,8 @@ class OnboardingCreateUser extends LitElement {
}
}
private async _submitForm(): Promise<void> {
private async _submitForm(ev): Promise<void> {
ev.preventDefault();
if (!this._name || !this._username || !this._password) {
this._errorMsg = "required_fields";
return;

View File

@ -108,7 +108,7 @@ class HaDialogAddUser extends LocalizeMixin(PolymerElement) {
super.ready();
this.addEventListener("keypress", (ev) => {
if (ev.keyCode === 13) {
this._createUser();
this._createUser(ev);
}
});
}
@ -131,7 +131,8 @@ class HaDialogAddUser extends LocalizeMixin(PolymerElement) {
}
}
async _createUser() {
async _createUser(ev) {
ev.preventDefault();
if (!this._name || !this._username || !this._password) return;
this._loading = true;