These are my current reactive form validations:
ngOnInit(): void {
this.userForm = this.formBuilder.group({
status: {checked: this.selectedUser.status == 1},
username: [this.selectedUser.username, [Validators.required, Validators.minLength(LlqaConstants.USERNAME_MIN_LENGTH)]],
realname: [this.selectedUser.realname, [Validators.required, Validators.minLength(LlqaConstants.REALNAME_MIN_LENGTH)]],
password: ['', this.selectedUser.passhash.length > 0 ? [Validators.required, Validators.minLength(LlqaConstants.PASSWORD_MIN_LENGTH)] : null],
usercomment: [this.selectedUser.comment]
});
}
I want to make the submit button enabled when at least one input value is different from the initial value. The method I tried is:
disableSaveButton(): boolean {
return !this.userform.dirty || this.userForm.invalid;
}
The issue with the dirty
property is that it becomes true as soon as any change is made, even if the new value is the same as the initial one. Is there a way to check only for values that have actually changed, rather than comparing all userForm.value
with this.selectedUser.someValue
?