我有反应形式:
protected _valueForm = this._formBuilder.group({
valueCaption: '',
});
protected _elementForm = this._formBuilder.group({
caption: ['', Validators.required],
required: [false]
});
然后ngOnInit()
有一个条件并且_elementForm
正在改变:
this._elementForm = this._formBuilder.group({
caption: ['', Validators.required],
required: false,
valueForm: this._valueForm,
values: this._formBuilder.array([])
},
{validator: FormElementValidator});
验证器:
export const FormElementValidator = (control: AbstractControl): ValidationErrors => {
const values = (control.get('values') as FormArray).value;
return (!!values.length) ? null : {noValues: 'T_FORM_VALUES_ARE_REQUIRED'};
}
而且效果很好,但是如果为空elementForm
,则无效。valueCaption
为什么会这样,我该如何解决?