I have reactive form validations set up as follows:
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'd like to enable the submit button, as soon as one input value is not equal to the initial value anymore. The simplest way I could find is:
disableSaveButton(): boolean {
return !this.userform.dirty || this.userForm.invalid;
}
My problem with the dirty property ist, as soon as I enter something, dirty is true, also if I enter the same value as the initial value. I'd to have a property which tells me if one input value is not equal to the initial value. Is this possible out of the box or do I have to check each userForm.value equals to this.selectedUser.someValue?