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

Why default validity is false? #19

Closed
zack9433 opened this issue Jun 9, 2014 · 15 comments
Closed

Why default validity is false? #19

zack9433 opened this issue Jun 9, 2014 · 15 comments
Labels
Milestone

Comments

@zack9433
Copy link
Contributor

zack9433 commented Jun 9, 2014

I think don't set validity to false when initial.

If i set a valid value to input as default value when initialize form and this input valid-method="blur", but i get this form $valid is false.

@hueitan
Copy link
Owner

hueitan commented Jun 9, 2014

Hi @zack9433

In this case,
after the form is blur, the $valid will change to true

Can you give me a DEMO to show the error you mention ?

@zack9433
Copy link
Contributor Author

zack9433 commented Jun 9, 2014

I create a sample
http://plnkr.co/edit/qYGiuD9MFINwgvY4JutZ?p=preview

@hueitan
Copy link
Owner

hueitan commented Jun 9, 2014

I suppose that you want to validate when initial

Here's for your reference:
https://github.com/huei90/angular-validation#can-i-validate-the-form-when-init--10
#10

@zack9433
Copy link
Contributor Author

zack9433 commented Jun 9, 2014

No, in my condition, the form has two part, one is default value and the other part is to let user to fill in.

I want check validation when user press submit.

@hueitan
Copy link
Owner

hueitan commented Jun 9, 2014

Ok @zack9433

For example you have

<!-- contain default value -->
<input type="text" ng-model="model1" validation="something"/>

<!-- let user fill -->
<input type="text" ng-model="model2" validation="other"/>

Then you can validate the first model

$validation.submit('model1')

Just validate the first one in Initial


And If you need the $validation.checkValid value, you have to $validation.submit first to get the latest checkValid value


Is that your question ?

@zack9433
Copy link
Contributor Author

zack9433 commented Jun 9, 2014

The form contains some default and user defined inputs and all inputs validate-method is blur and I want call $validation.checkValid on submit to check current form validation state.

I think i will get form validation is true in two condition:

  1. I directly press submit without modifying inputs
  2. I fill in user defined input without modifying any default input value.

Both condition will get false because validity is false by default.
So, why set validity to false when init?

@hueitan
Copy link
Owner

hueitan commented Jun 10, 2014

Thanks @zack9433
This is kind of bug.

Can you give me a PR on this ? (Coz i need some time to fix this after my other work) unless you can wait

check initial has value, then check $validity to true or false based on the default given value.

@hueitan hueitan added the bug label Jun 10, 2014
@hueitan
Copy link
Owner

hueitan commented Jun 10, 2014

Hi @zack9433

I have found your DEMO issue here

$scope.submitForm = function(form) {
    $scope.result = $validationProvider.checkValid(form);
}

checkValid() is kind of manually check, it just get the latest valid status. #

We should use this with the validate method,
after the validate method, checkValid() can get the real latest valid status.

For example

$scope.submitForm = function (form) {
    $validationProvider.validate(form)
       .success(function () {
           $scope.result = $validationProvider.checkValid(form);
     });
}

This will get the real answer. 🍻

@zack9433
Copy link
Contributor Author

Thanks @huei90

But i think don't set validity when init is better than set to false. 🍻

@hueitan
Copy link
Owner

hueitan commented Jun 10, 2014

Ok, i heard your voice =)

@hueitan hueitan added this to the 1.2.0 milestone Jun 11, 2014
@hueitan
Copy link
Owner

hueitan commented Jun 15, 2014

Hi @zack9433

I'm going to close this issue.

Whether set init validity to true false null are facing the same problem.

using checkValid to get the latest result, you have to execute submit first
That's only I can suggest.

I will add the Q&A section by reference to this issue =) #

@hueitan
Copy link
Owner

hueitan commented Nov 18, 2014

Hi @zack9433

angularjs 1.3 solve this problem.
a30e6ed

for your reference 😄

@zafarullahjoiya
Copy link

i am facing a strange problem.i am really tired to configure this problem.i see the default value of $valid is false when user fill the form correctly it become true then submit button enable.can any one tell me here how we can set the default value of $valid false instead of true ?

@hueitan
Copy link
Owner

hueitan commented May 8, 2015

Hi @zafarullahjoiya Sorry that I didn't mentioned this on the Document.

Here's you can change the Initial value of $valid
https://github.com/huei90/angular-validation/blob/master/API.md#customizable-initial-validation

@zafarullahjoiya
Copy link

HI Huei Tan

Thanks for response....i have resolve the issue...The issue was with
ng-model.
Thanks once again

zafarullahjoiya

On Thu, May 7, 2015 at 6:34 PM, Huei Tan [email protected] wrote:

Hi @zafarullahjoiya https://github.com/zafarullahjoiya Sorry that I
didn't mentioned this on the Document.

Here's you can change the Initial value of $valid

https://github.com/huei90/angular-validation/blob/master/API.md#customizable-initial-validation


Reply to this email directly or view it on GitHub
#19 (comment)
.

Web Developer

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

3 participants