formHelper.expectValidChange('oldpassword', 'foo');
});
+ it('should validate old and new password must be different', () => {
+ formHelper.setMultipleValues({
+ oldpassword: 'aaa',
+ newpassword: 'aaa'
+ });
+ formHelper.expectError('oldpassword', 'notmatch');
+ formHelper.expectError('newpassword', 'notmatch');
+
+ formHelper.setValue('newpassword', 'bbb');
+ formHelper.expectValid('oldpassword');
+ formHelper.expectValid('newpassword');
+ });
+
it('should validate password match', () => {
formHelper.setValue('newpassword', 'aaa');
formHelper.expectErrorChange('confirmnewpassword', 'bbb', 'match');
validators: [CdValidators.match('newpassword', 'confirmnewpassword')]
}
);
+
+ this.userForm.get('oldpassword').valueChanges.subscribe(() => {
+ this.userForm.get('newpassword').updateValueAndValidity({ emitEvent: false });
+ });
+ this.userForm.get('newpassword').valueChanges.subscribe(() => {
+ this.userForm.get('oldpassword').updateValueAndValidity({ emitEvent: false });
+ });
}
onSubmit() {
formHelper.expectValid('x');
formHelper.expectError('y', 'notUnique');
});
+
+ it('should not error when confirm value is empty', () => {
+ formHelper.setValue('y', '');
+ CdValidators.match('x', 'y')(form);
+ formHelper.expectValid('y');
+ });
});
describe('unique', () => {
if (!ctrl1 || !ctrl2) {
return null;
}
- if (ctrl1.value !== ctrl2.value) {
+ if (ctrl2.value && ctrl1.value !== ctrl2.value) {
const errors = _.merge({}, ctrl2.errors, { match: true });
ctrl2.setErrors(errors);
} else {