fix(forms): disabled controls should never be invalid (#11257)
Closes #11253
This commit is contained in:
parent
2581c0851a
commit
043493cb62
|
@ -360,10 +360,10 @@ export abstract class AbstractControl {
|
||||||
|
|
||||||
|
|
||||||
private _calculateStatus(): string {
|
private _calculateStatus(): string {
|
||||||
|
if (this._allControlsDisabled()) return DISABLED;
|
||||||
if (isPresent(this._errors)) return INVALID;
|
if (isPresent(this._errors)) return INVALID;
|
||||||
if (this._anyControlsHaveStatus(PENDING)) return PENDING;
|
if (this._anyControlsHaveStatus(PENDING)) return PENDING;
|
||||||
if (this._anyControlsHaveStatus(INVALID)) return INVALID;
|
if (this._anyControlsHaveStatus(INVALID)) return INVALID;
|
||||||
if (this._allControlsDisabled()) return DISABLED;
|
|
||||||
return VALID;
|
return VALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,13 @@ export function main() {
|
||||||
expect(c.status).toBe('DISABLED');
|
expect(c.status).toBe('DISABLED');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should honor boxed value with disabled control when validating', () => {
|
||||||
|
const c = new FormControl({value: '', disabled: true}, Validators.required);
|
||||||
|
expect(c.disabled).toBe(true);
|
||||||
|
expect(c.valid).toBe(false);
|
||||||
|
expect(c.status).toBe('DISABLED');
|
||||||
|
});
|
||||||
|
|
||||||
it('should not treat objects as boxed values if they have more than two props', () => {
|
it('should not treat objects as boxed values if they have more than two props', () => {
|
||||||
const c = new FormControl({value: '', disabled: true, test: 'test'}, null, null);
|
const c = new FormControl({value: '', disabled: true, test: 'test'}, null, null);
|
||||||
expect(c.value).toEqual({value: '', disabled: true, test: 'test'});
|
expect(c.value).toEqual({value: '', disabled: true, test: 'test'});
|
||||||
|
|
Loading…
Reference in New Issue