When using igx-input-group, there is no UI feedback after ReactiveForm's markAsTouched is called.
Description
When using igx-input-group, there is no UI feedback after ReactiveForm's markAsTouched is called.
Steps to reproduce
- Go to https://stackblitz.com/edit/igx-editors-v5-2-1 (using igx-form-group class)
- Click "SUBMIT" button
- Go to https://stackblitz.com/edit/igx-editors-issue (using igx-input-group component)
- Click "SUBMIT" button
Result
On the step 4, there is no UI feedback.
Expected result
There should be UI feedback.
I used igx-form-group class before and it worked well. I want igx-input-group to work as well.
@tkiryu sorry, I can't open the samples.
@simeonoff , I'm sorry about that.
Here is the first link. https://stackblitz.com/edit/igx-editors-v5-2-1
Here is the second link. https://stackblitz.com/edit/igx-editors-issue
I have fixed the links in the Steps to reproduce as well.
@tkiryu I have just committed a fix for this. However, it requires a small change in the sample for it to work properly. Since markAsTouched simply sets the form control's touched field to true, we have no way of reacting to it, so you need to call updateValueAndValidity after you call markAsTouched:
if (!this.form.valid) {
for (let key in this.form.controls) {
this.form.controls[key].markAsTouched();
this.form.controls[key].updateValueAndValidity();
}
}
Note, that it used to work previously as we had a style that was applied when angular adds ng-touched to the component's classlist, but this is no longer the case.
@DDavidkov ,
I understand why we need to call updateValueAndValidity. Thank you for your great work!
https://github.com/IgniteUI/igniteui-angular/commit/d56386b8cc310e9ba6a140aec0637847699dc083#diff-6f41a12bd84d5e6d3bad3cad109e10c3R125
Note, that it used to work previously as we had a style that was applied when angular adds ng-touched to the component's classlist, but this is no longer the case.
I'm a little concerned. For example, when just focusing in/out an input, Reactive Forms adds ng-touched class but doesn't emit statusChanges. So I guess IgxInput cannot know whether the input has been touched or not.
@tkiryu, yes what you just explained is essentially the issue here and why we need to call updateValueAndValidity
@DDavidkov What I was concerned about was resolved by your additional commit. Thank you so much! https://github.com/IgniteUI/igniteui-angular/commit/b0cf011dd5b66bd994c1436b6ac7de054e3d7897#diff-6f41a12bd84d5e6d3bad3cad109e10c3R81
Has this required workaround been put in public docs?
@kdinev
@kdawg1406 It's not yet in the docs, but it's on the TODO list.
@tkiryu do you have a working project you can share?
@tkiryu the above workaround is no longer required. This sample shows the new ways to work with ReactiveForms and radio buttons.
https://stackblitz.com/angular/xlodgdreenr?file=app%2Fradio-group-sample%2Fradio-group-sample.component.ts
@kdawg1406 if the initial value of fullName is blank, igx-input-group doesn't get any UI feedback after clicking Submit button.
https://stackblitz.com/edit/angular-t9inrw
So I think we still need to call updateValueAndValidity, though...
Could you tell me your thoughts on this?
By the way, here is my sample using updateValueAndValidity.
https://stackblitz.com/edit/igx-editors-issue
@tkiryu not sure about this. You should do what you need to do to make it work. I'm just glad the UI issue was addressed.