material icon indicating copy to clipboard operation
material copied to clipboard

Validation does not work correctly

Open IPRIT opened this issue 11 years ago • 11 comments

In version 0.8.0 if you install required on the input and enter a couple of characters the field will remain red.

    <md-input-container flex>
        <label>
            <my-i18n msgid="company_register_company_zip"></my-i18n>
        </label>
        <input required type="text" name="zip" ng-model="company.zip">
        <div ng-messages="companyRegister.zip.$error">
            <div ng-message="required">
                <my-i18n msgid="error_required_field"></my-i18n>
            </div>
        </div>
    </md-input-container>

Awesome example

IPRIT avatar Feb 21 '15 22:02 IPRIT

Are you loading the angular-messages library?

< script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-messages.js"> + var app = angular.module('App', ['ngMaterial', --> 'ngMessages'] <--- );

I've got the same problem 20 minutes ago :)

luclanet avatar Feb 21 '15 23:02 luclanet

I am seeing the same problem as well. What was odd if I implemented the md-is-error attribute, for example:

md-is-error="!(model.name.length > 0)"

It is working, but that shouldn't be needed. The field is getting the ng-invalid class applied even though the model value is present. Adding the above fixes that but seems a bit of a hack.

jadrake75 avatar Feb 22 '15 05:02 jadrake75

this might be related to autofocus attribute..... let me try it with a plunkr

jadrake75 avatar Feb 22 '15 06:02 jadrake75

ok, I haven't isolated the problem but there is definitely sequences that cause it. Something is amiss.

Here is a plunkr that has instructions: http://plnkr.co/edit/OducT5RggtbFjBXZNykS?p=preview

I am NOT using the md-is-error in this case, which means it is using the closure of

function() { return ngModelCtrl.$invalid && ngModelCtrl.$touched; }

And this may be the problem, since the field WITH md-is-error never shows the problem.....

jadrake75 avatar Feb 22 '15 06:02 jadrake75

This issue began sometime after the 0.7.1 release.

It looks as though it's only a problem when using the required attribute. Here's a CodePen that shows the issue. If you input valid values for the fields initially, the required error is still present. However, if another validator produces an error (i.e. by entering a value that's too long in the name field or a negative or non-integer value in the age field), then the error for required gets cleared and all is well. Additionally, the occupation field uses a custom req directive for comparison.

This behavior is also present in the docs for the input component, in the client name field of the errors example.

ngraef avatar Feb 23 '15 20:02 ngraef

I confirm this behavior

spacenick avatar Feb 23 '15 23:02 spacenick

+1 confirmed bug on 0.8.0 when didn't exist in 0.7.1

arush avatar Feb 24 '15 21:02 arush

I just opened #1645, which is a more strict use case, but may be related to this one.

gustavohenke avatar Feb 24 '15 21:02 gustavohenke

+1 Behavior has changed since 0.7.1 if required is set

kschwidder avatar Feb 26 '15 20:02 kschwidder

It looks like this issue is fixed with the commit 747eb9c3f493dfc338901f66108042ca78b5936e from @ThomasBurleson It works for me at least.

ruant avatar Feb 27 '15 14:02 ruant

Related: #1485.

Yup, looks like this was fixed by 747eb9c3f493dfc338901f66108042ca78b5936e.

ngraef avatar Feb 27 '15 16:02 ngraef