question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mat-select with validation not kicked when focus is lost

See original GitHub issue

Bug, feature request, or proposal:

In my opinion bug with mat-select. The error message is not visible when dropdown is closed; focus is not behaving properly with “required” attribute applied.

What is the expected behavior?

When focus is not on the control anymore, the error message should be visible.

What is the current behavior?

When focus is lost, the error message is not immediately visible.

What are the steps to reproduce?

  1. http://plnkr.co/edit/K6hyF9?p=preview
  2. Click on “favorite options” on the left hand side
  3. Click out of dropdown to cancel the selection
  4. Notice the visible “this field is required message”
  5. Click on “favorite food” image image
  6. click out of dropdown to cancel the selection
  7. notice that “this field is required” is not visible + the bottom line thickness is a little bit bigger than standard image
  8. click again outside of the control, to remove focus on the control
  9. the “this field is required” message is visible now image

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

As on the plunker shown, autocomplete is behaving move intuitevly when deselecting / closing the dropdown. Validation occurs immediatelly as you would expect it. With mat-select it’s not. In order to kick off the validation, you need to click twice somewhere on the form (some sort).

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

material: 5.0.0-rc.1-6a9fbfe angular: as for version above OS: win 10 64bit enterprise browser: all

Is there anything else we should know?

nope, keep up the good work over this repository 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
k-krupkacommented, Nov 21, 2017

@willshowell this is not what I would expect. I would expect the mat-select to behave like mat-autocomplete in this example (plunker above). I am explicitly clicking outside of select’s expanded dropdown to deselect, ergo to loose the focus from the control. I don’t want to do extra click to “actually” quit the control and then to loose focus 😃 😃

If we take the situation as you say, it means that in autocomplete there is a bug, because the focus is lost when you deselect the value.

Using keyboard keys as you mentioned is not showing the issue. Using keyboard this is behaving properly as expected. True that.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mat-select required validation not working - Stack Overflow
Since I want the "selection" is a required field, the "submit" button should be disabled when the form is rendered. However, the "submit"...
Read more >
Select | Angular Material
<mat-select> is a form control for selecting a value from a set of options, similar to the native <select> element. You can read...
Read more >
Working with Angular 4 Forms: Nesting and Input Validation
Validating user inputs is an essential part of any robust web application. Angular 4 makes it especially easy for both template-driven and reactive...
Read more >
Angular Form Validation on Blur and Submit - Fiyaz Hasan
That's cool but not the behavior you want when you have several Form Controls in your form model for performance reasons. But you...
Read more >
Angular Reactive Forms: trigger validation on submit
For this example, we will consider a field has validation error when the field is not valid and it has been touched (meaning...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found