Skip to content

Commit d48c3ae

Browse files
committed
Handles null on form
1 parent fc1dd6d commit d48c3ae

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/app/login/components/login-form/login-form.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@ export class LoginFormComponent {
2626

2727
public onLogin() {
2828
if (this.form.valid) {
29-
this.login.emit(this.form.value);
29+
if ((this.form.value.username) && (this.form.value.password)) {
30+
const user = new LoginUser();
31+
user.username = this.form.value.username;
32+
user.password = this.form.value.password;
33+
34+
this.login.emit(user);
35+
}
3036
}
3137
}
3238

3339
public isFormInvalid(field: string): boolean {
3440
let invalid: boolean;
3541

36-
if(this.form.invalid) {
42+
if (this.form.invalid) {
3743
const formField = this.form.get(field);
38-
if(formField){
44+
if (formField) {
3945
invalid = (formField?.dirty || formField?.touched) && (formField?.errors != null);
4046
} else {
4147
invalid = false;

0 commit comments

Comments
 (0)