-
Notifications
You must be signed in to change notification settings - Fork 749
How to mark custom form control as dirty/touched? #3191
Comments
This is a limitation in Angular currently that is being tracked by angular/angular#10887. I suggest looking at some of the workarounds proposed there for your form control to get an instance of your FormControl, and then be able to call the appropriate markAs methods. Also see https://stackoverflow.com/questions/44730711/how-do-i-know-when-custom-form-control-is-marked-as-pristine-in-angular. Closing as an issue with Angular. |
@gnomeontherun examples you posted works perfectly but with use From the previous example if I add to @Input() control: FormControl;
...
ngOnInit() {
this.control.markAsTouched = function() {
console.log('Control marked as touched');
};
} where onFormSubmit() {
if (this.form.invalid) {
// this.clrForm.markAsDirty();
this.markFormGroupTouched(this.form);
return;
}
}
private markFormGroupTouched(form: FormGroup) {
Object.values(form.controls).forEach(control => {
control.markAsTouched();
if ((control as any).controls) {
this.markFormGroupTouched(control as FormGroup);
}
});
} As you can see in that scenario I don't use |
The purpose of I haven't tested this with custom form components, but if you wanted to make a stackblitz demo that would help so I can actually see what you're doing. Either way, this is turning into a how-to kind of topic which we typically handle on StackOverflow. |
How can I mark a form controle as unTouched. |
@azad47808 : Have you tried resetting the formControl? |
Hi there 👋, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary. |
Issue
When using the custom form control that implements Angular's
ControlValueAccessor
interface it isn't marked as touched/dirty whenmarkAsDirty()
method ofClrForm
is called.Code examples
component.ts
where
type
,sender
andreceiver
fields are used by custom form controls.component.html
custom-form-control.ts
custom-form-control.html
In source codes of the Clarity, I found
MarkControlService
that seems to be used to mark controls as dirty/touched but can't figure it out how to use with custom form control or if it possible even?Any ideas about how it can be achieved?
The text was updated successfully, but these errors were encountered: