Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the very first character is written on an input, it is not binded with $scope, and then $invalid flag takes a wrong value #60

Open
jesusjiib opened this issue Jan 23, 2015 · 7 comments
Labels

Comments

@jesusjiib
Copy link

Hello!

First of all, I would like to thank you for this great and useful library.

I have detected an issue when an angular-ui-form-validation directive is assigned to a form input field:

  1. I code a sample html form, dumping $scope.name and $invalid variables:
    code1

As you could see below, the result is correct, since $scope.name='' and $invalid=false:
sampleform

  1. Here comes the issue: When the very first character is written on the input field, it is expected that $scope.name='a' and $invalid=false, however, the input is not binded with its corresponding $scope variable, and then $invalid is set to true:
    sampleform2

  2. Then, I insert the second character. After this, the variable is binded and the validation process works fine
    sampleform3
    If I delete the just inserted character, then the directive is still working:
    sampleform4

  3. After step 3, if I delete the last character and the input lost the focus, the validation directive works fine
    sampleform5

  4. Then, if I put another random character, the validation works
    sampleform6

Any ideas/solutions? Thank you very much

@jesusjiib jesusjiib changed the title When the very first character is written on an input, it is not binded with $scope, and then $invalid flag takes a worng value When the very first character is written on an input, it is not binded with $scope, and then $invalid flag takes a wrong value Jan 23, 2015
@nelsonomuto
Copy link
Owner

I just ran a test for this in my debugger and I don't see the issue. Everything is firing as expected and the binding is accurate.

In the validator, you can inspect the form model controller, it is passed in as the 6th parameter, it corresponds to sampleForm.namefield (the form controller model property)

function (errorMessageElement, val, attr, $element, model, ngModelController, $scope, rawAttr) {

@nelsonomuto
Copy link
Owner

As far as the UI bound value {{sampleForm.username.$valid}}, you are correct to observe that it does not update on the first run of the validation. However the value is accurately updated in the validator function corresponding value ngModelController.$valid. Not sure why the binding is not kicked off initially on the first run. But I will keep testing, good catch.

@jesusjiib
Copy link
Author

Thank you very much. I'll wait for a resolution. I cannot try to solve the bug since the source code is minified.

PD. By the way, something similar happens when CTRL-C/CTRL-V is done on the input.

@jesusjiib
Copy link
Author

I just realize that this bug appears when using AngularJS>=1.3.0. With AngularJS 1.2.x the custom validation library works fine.

@nelsonomuto
Copy link
Owner

I am looking into it currently.

@nirmaladdon
Copy link

@nelsonomuto Have you checked ?
i am also facing this problem

@krunalshah68
Copy link

Yep faced same issue today. Model is not updating on first time input and unfortunately form gets invalidated. This causes major issue in form validation. Hope it gets fixed ASAP.
P.S: I'm using custom validation created in my custom module.

inicolenco pushed a commit to inicolenco/angular-ui-form-validation that referenced this issue Sep 8, 2016
nelsonomuto added a commit that referenced this issue Sep 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants