Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Validation does not work correctly #1606

Closed
IPRIT opened this issue Feb 21, 2015 · 11 comments
Closed

Validation does not work correctly #1606

IPRIT opened this issue Feb 21, 2015 · 11 comments

Comments

@IPRIT
Copy link
Contributor

IPRIT commented Feb 21, 2015

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

@luclanet
Copy link

Are you loading the angular-messages library?

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

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

@jadrake75
Copy link

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
Copy link

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

@jadrake75
Copy link

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.....

@ngraef
Copy link
Contributor

ngraef commented Feb 23, 2015

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.

@spacenick
Copy link

I confirm this behavior

@arush
Copy link

arush commented Feb 24, 2015

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

@gustavohenke
Copy link

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

@kschwidder
Copy link

+1 Behavior has changed since 0.7.1 if required is set

@ruant
Copy link

ruant commented Feb 27, 2015

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

@ngraef
Copy link
Contributor

ngraef commented Feb 27, 2015

Related: #1485.

Yup, looks like this was fixed by 747eb9c.

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

9 participants