Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

touched/untouched not updating in custom input component #10151

Closed
sharpmachine opened this issue Jul 19, 2016 · 6 comments
Closed

touched/untouched not updating in custom input component #10151

sharpmachine opened this issue Jul 19, 2016 · 6 comments

Comments

@sharpmachine
Copy link

I'm submitting a ... (check one with "x")

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
untouched/touched properties do not update, but ng-touched class is being added properly, but pristine/dirty and validators do.

Expected/desired behavior
I would expect untouched/touched to updated on blur, just like pristine/dirty and validators are.

Reproduction of the problem
https://plnkr.co/edit/O9KWzwhjvySnXd7vyo71?

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser:
    Chrome 51
  • Language:
    Typescript
@zoechi
Copy link
Contributor

zoechi commented Jul 19, 2016

You need to call onTouched() (this._onTouchedCallback) from inside your component when you want the controls status set to touched. Same for this._onChangeCallback

For example by adding (ngModelChange)="onTouched(value)" to the <input> in my-custom-input

GitHub issues are for bug reports and feature requests.
For support questions please use other channels like the ones listed in CONTRIBUTING - Got a Question or Problem?

@sharpmachine
Copy link
Author

Sorry @zoechi I edited the Plunker after you looked it. I added (blur)="onTouched($event)" to the input. But it still looks a bug to me because touched/untouched state is meant to update on blur. If I just click into the field and then off the field, it updated, however if I actually type something into the field, then click off, the touched/untouched state does not update.

https://plnkr.co/edit/O9KWzwhjvySnXd7vyo71

@zoechi
Copy link
Contributor

zoechi commented Jul 19, 2016

This is because

<p *ngIf="control.errors.required

throws an exception and then the blur handler doesn't work anymore

If you change it to
<p *ngIf="control?.errors.required all is working as desired.

Please always check the browser console...

@sharpmachine
Copy link
Author

I had to change it to <p *ngIf="control?.errors.required

Thanks.

@yash5862
Copy link

yash5862 commented Jan 5, 2018

What if i want to check if control is touched or not in this..?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants