Skip to content

Instantly share code, notes, and snippets.

@Armenvardanyan95
Created September 5, 2025 10:21
Show Gist options
  • Save Armenvardanyan95/803cd92c674659e27a2b6f2458af4e83 to your computer and use it in GitHub Desktop.
Save Armenvardanyan95/803cd92c674659e27a2b6f2458af4e83 to your computer and use it in GitHub Desktop.
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