Created
September 5, 2025 10:21
-
-
Save Armenvardanyan95/803cd92c674659e27a2b6f2458af4e83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function passwordsEqual(path: FieldPath<{ | |
password: string; confirmPassword: string | |
}>) { | |
validate(path, (ctx) => { | |
const value = ctx.value(); | |
if (value.password !== value.confirmPassword) { | |
return customError({ kind: 'notEqual', message: 'Passwords must match' }); | |
} | |
return null; | |
}); | |
} | |
@Component({ | |
template: | |
<form> | |
<label for="email">Email:</label> | |
<input id="email" type="email" [control]="form.email" /> | |
<label for="password">Password:</label> | |
<input id="password" type="password" [control]="form.password" /> | |
<label for="confirmPassword">Confirm Password:</label> | |
<input id="confirmPassword" type="password" [control]="form.confirmPassword" /> | |
@for (error of form().errors(); track error.kind) { | |
<span class="error">{{ error.message }}</span> | |
} | |
<button type="submit" [disabled]="form().invalid()"> | |
Login | |
</button> | |
</form>, | |
}) | |
export class Register { | |
private credentials = signal({ | |
email: '', | |
password: '', | |
confirmPassword: '', | |
}); | |
protected readonly form = form( | |
this.credentials, | |
credentials => { | |
passwordsEqual(credentials); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment