material icon indicating copy to clipboard operation
material copied to clipboard

ngMessages is not working as expected

Open prakashjp123 opened this issue 10 years ago • 38 comments

I am using ngMessage with angular material. But it doesn't working as expected. I have my code here.

The problem is once the error message is displayed, when another new error is appeared and the existing error is disappeared then it breaks. For above example, click on the input and click outside of it. You will receive the required error. Now when you try inserting any character, the required error disappeared and the email error should appear. But this is not working.

prakashjp123 avatar Dec 22 '15 11:12 prakashjp123

<div ng-app="app" ng-controller="FormController" layout-padding>
  <form name="inputForm">
    <md-input-container>
      <label>Input Value</label>
      <input type="email" name="email" ng-required="true" ng-pattern="/^.+@.+\..+$/" ng-model="model.value" />
      <div ng-messages="inputForm.email.$error">
        <div ng-message-exp="['required', 'pattern']">E-mail is not valid</div>
      </div>
    </md-input-container> 
    <div>inputForm.inputValue.$error = {{inputForm.email.$error | json}}</div>
  </form>
</div>

ghost avatar Dec 22 '15 12:12 ghost

I have the same issue with the newest update of material and angular

ebastuart avatar Dec 22 '15 13:12 ebastuart

Another issue here is that error message does not show initially for required input field.

gregorst avatar Dec 22 '15 14:12 gregorst

on the last bit, I think it is by design... I have discussed this with users a number of times, and they don't seem to like being presented with error messages until they at least enter something, so the idea that ng-messages are hidden until the related field has been $touched seems good to me.

Messages that should be displayed even before the user interacts with a field seem to me to be labels or input hints.

FrancescoRizzi avatar Dec 22 '15 18:12 FrancescoRizzi

Same issue here on ng-material 1.0.0, 1.0.1 and angular 1.4.6 and 1.4.8.

Update: adding md-auto-hide="false" solves my problems. I can now add ng-show="form2.username.$touched" to hide on page load and voila, I'm golden.

rsteenbergen avatar Dec 22 '15 20:12 rsteenbergen

@FrancescoRizzi: I thought so. At least we need a way to enable this. And suggestion from @rsteenbergen is exactly what we need. This is also described in docs.

gregorst avatar Dec 23 '15 09:12 gregorst

I think the hide animation works after the element appears into the display section. So it hides all messages. Is there any way to solve the issue temporarily?

prakashjp123 avatar Dec 25 '15 19:12 prakashjp123

@rsteenbergen thanks - that helped me

simonh1000 avatar Jan 08 '16 12:01 simonh1000

NgMessage behave erratically with angular-material. Here is a plunker: http://embed.plnkr.co/SWJFsOS3BuxYxePBQZ0C/

It works fine with just the required validation check, but if I add another, like min for instance, then sometimes the error message isn't shown at all. Without angular-material it works fine.

Form Without Angular-Material Initial screen shot 2016-01-22 at 4 37 53 pm

When I enter a value < 400: 2

Form With Angular-Material I enter a small value: screen shot 2016-01-22 at 4 38 38 pm

I erase everything: screen shot 2016-01-22 at 4 38 31 pm

I enter a value greater than 400 and then erase everything: screen shot 2016-01-22 at 4 38 51 pm

UPDATE: Fixed it thanks to @rsteenbergen, linked plunker now has updated code.

ketanbhatt avatar Jan 22 '16 11:01 ketanbhatt

So this is resolved?

EladBezalel avatar Jan 22 '16 22:01 EladBezalel

Well @rsteenbergen provided a workaround, but is that the solution we want? Shouldnt it 'just work' with ngMessages instead of users having to add rsteenbergen's solution.

joerideg avatar Jan 25 '16 12:01 joerideg

I'm seeing the same problem and agree with @joerideg . It is erratic so I hesitate to use the md-hide workaround to get it to work more often.

Update: While I have noticed strange behavior with the appearance of the messages, this time it was my mistake. I accidentally left off the input's name attribute. Sorry!

longrunningprocess avatar Jan 30 '16 06:01 longrunningprocess

Using md-auto-hide="false" isn't a great fix, since all errors will display by default, which can be overwhelming for someone filling out a new empty form.

langdonx avatar Feb 02 '16 16:02 langdonx

I have the same problem here with angular 1.5.0 and angular-material 1.0.5. Also after I updated angular-material from 1.0.1 the error pushes content down instead of appearing in md-errors-spacer

you can see it's even in official demo https://material.angularjs.org/latest/demo/input

dnevzorov avatar Feb 25 '16 10:02 dnevzorov

Confirming this too (angular 1.5.0 + angular-material 1.0.5).

andrey-bahrachev avatar Feb 28 '16 16:02 andrey-bahrachev

Any fix on this?

dnevzorov avatar Mar 01 '16 12:03 dnevzorov

+1

pablozandona avatar Mar 15 '16 18:03 pablozandona

+1

danpii avatar Mar 16 '16 22:03 danpii

same here

2nise avatar Mar 17 '16 08:03 2nise

+1

danielebuso avatar Mar 17 '16 08:03 danielebuso