Skip to content

md-input-container invalid state #4671

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

Closed
mbeckenbach opened this issue May 19, 2017 · 8 comments
Closed

md-input-container invalid state #4671

mbeckenbach opened this issue May 19, 2017 · 8 comments

Comments

@mbeckenbach
Copy link

Bug, feature request, or proposal:

question, bug, or feature request. not sure

What is the expected behavior?

When a user enters text into a required input field and removes the text, there should be an immediate warning as the form control is now touched.

What is the current behavior?

The invalid color and md-error text are only updated after blur.

required

What are the steps to reproduce?

<md-input-container>
      <input mdInput formControlName="answer" [required]="true">
     <md-error *ngIf="answerControl.errors?.required">Dies ist ein Pflichtfeld.</md-error>
</md-input-container>

What is the use-case or motivation for changing an existing behavior?

better user experience

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

ng4.1.x, md beta 5

Is there anything else we should know?

@willshowell
Copy link
Contributor

Error state is calculated as

isInvalid && (isTouched || isSubmitted)

and touched is true when the control has been focused and then blurred.

There's an open issue at #4232 that could be of interest.

@mbeckenbach
Copy link
Author

ok, but where does isSubmitted come from? My control does not change to submitted when i submit the form

@willshowell
Copy link
Contributor

See the source here

@mbeckenbach
Copy link
Author

@willshowell yes, but there is no submitted property on my form, also in my usecase i cannot use a submit button to submit my form.

image

@willshowell
Copy link
Contributor

Hmm I see. I think for your original question, your best bet is to push the team on #4232 since that would allow you to configure how the errors are shown.

As a workaround for now, you could bind to the focus event and use myFormControl.markAsTouched(). I think that would get the error to show up immediately.

@mbeckenbach
Copy link
Author

ok found a workarround. I created a hidden submit button and an event listener for my custom form submitted event:

´´´
formSubmittedSubscription = this.surveyService.formSubmittedChange.subscribe(value => {
this.formSubmitted = value;
this.submitBtn.nativeElement.click();
});

@ViewChild('submitBtn') submitBtn: ElementRef;
´´´

@jelbourn
Copy link
Member

Tracked via #4232

@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 5, 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