material icon indicating copy to clipboard operation
material copied to clipboard

md-input-container not showing error ng-messages

Open vlio20 opened this issue 10 years ago • 75 comments

Hi, There are cases when the error message (ng-message) not showing, try to play with the codepen below. the input field is required and minlength set to 2: http://codepen.io/vlio20/pen/KVybvx?editors=110

Steps to reproduce:

  1. focus on input.
  2. enter 1 char & focus out (blur) -> minlength error message is displayed.
  3. delete the char from step 2 -> no message is displayed, when the required message should have been displayed.

Note-1: The form is invalid with correct message

Note-2: in happens for other validations as well (other then required and minlength). If I am overriding the styles like bellow, it seems to be working, but the animations are not good when the error message is changed:

md-input-container.md-input-invalid .md-auto-hide .md-input-message-animation:not(.ng-animate) {
  opacity: 1;
  margin-top: 0;
}

md-input-container.md-input-invalid [ng-messages] {
  max-height: 19px;
}

I am using 1.0.2 version, but it seems to be broken since 1.0.0

vlio20 avatar Jan 19 '16 21:01 vlio20

update: codepen

+1 - I am doing custom messaging for server-side errors with ng-messages using an md-input-container, and I'm running into the same issue.

<md-input-container>
  <div ng-messages="vm.loginServerErrors"
       role="alert">
    <div ng-message="loginFailed">
      Oops! That username and password combination was incorrect.
    </div>
  </div>
</md-input-container>

This code worked with v0.11, but no longer works after bumping to 1.0. Looking into the DOM on the rendered page, the class md-auto-hide is getting applied to the ng-messages div. Removing this class restores the original behavior.

persimmons avatar Jan 20 '16 19:01 persimmons

@keithajackson, did you add some custom code to fix this?

vlio20 avatar Jan 20 '16 19:01 vlio20

@vilo20 I was hoping to avoid it, but it's looking like I have to override a CSS style to make a workaround:

The offending rules (which are getting applied to the ng-message children, not the ng-messages parent, are:

md-input-container .md-auto-hide .md-input-message-animation:not(.ng-animate) {
    opacity: 0;
    margin-top: -100px;
}
md-input-container:not(.md-input-invalid) .md-auto-hide .md-input-message-animation {
    opacity: 0;
    margin-top: -100px;
}

persimmons avatar Jan 20 '16 19:01 persimmons

update: codepen with fix

GOT IT. I needed to disable auto-hiding on my ng-messages div, changing:

<div ng-messages="rgn.loginServerErrors" role="alert">

to

<div ng-messages="rgn.loginServerErrors" role="alert" md-auto-hide="false">

The md-input docs note that messages will automatically be hidden until the md-input-container sets an md-is-error expression. Since my use case doesn't use md-input-container for anything besides (essentially) styling, I'm handling the visibility myself through JS.

persimmons avatar Jan 20 '16 19:01 persimmons

Workaround: I made a somewhat fixed codepen off your issue, @vlio20 , by handling the visibility myself:

<div ng-messages="registrationForm.agencyName.$error" md-auto-hide="false" ng-if="registrationForm.agencyName.$touched">

The animations get weird, though when I follow the steps to reproduce. Both errors become visible for a moment, and then the minlength error disappears without an animation.

persimmons avatar Jan 20 '16 19:01 persimmons

@keithajackson, yea it worked! thanks!!! I think it should be the default behavior.
Now I have very long html tags :(

Thanks @keithajackson, I will close this issue.

vlio20 avatar Jan 20 '16 20:01 vlio20

@vlio20 I think we should keep this open. The workaround fix still results in broken animations, so I think the underlying feature has a bug.

Open codepen, then:

  1. focus on input.
  2. enter 1 char & focus out (blur) -> minlength error message is displayed.
  3. delete the char from step 2 -> second message slides in, bumping elements down. Then the first message disappears, snapping everything back up.

persimmons avatar Jan 20 '16 20:01 persimmons

Hi guys, thanks for the workaround. Keep the issue open I just ended up here having the same problem as you guys. Lets hope for a real fix soon that will also fix the animation.

brunsgaard avatar Jan 21 '16 02:01 brunsgaard

A full, valid PR would be welcomed.

ThomasBurleson avatar Jan 27 '16 04:01 ThomasBurleson

Based on this conversation, ng-messages are effectively not working with angular material? Is that what I'm seeing?

stephengardner avatar Feb 27 '16 05:02 stephengardner

You are right. It's not even an edge case

vlio20 avatar Feb 27 '16 07:02 vlio20

+1

photusenigma avatar Mar 01 '16 18:03 photusenigma

+1

dougpix avatar Mar 01 '16 18:03 dougpix

+1

volmerf avatar Mar 03 '16 12:03 volmerf

+1

jobo26 avatar Mar 03 '16 12:03 jobo26

+1

pjwalmsley avatar Mar 03 '16 20:03 pjwalmsley

+1

danidewitt avatar Mar 03 '16 21:03 danidewitt

+1

galharth avatar Mar 07 '16 12:03 galharth

+1

autumnfjeld avatar Mar 08 '16 21:03 autumnfjeld

+1

tomiplaz avatar Mar 09 '16 16:03 tomiplaz