Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

unbind 'blur' in cancelValidation() #28

Closed
LennyLip opened this issue Apr 19, 2015 · 16 comments
Closed

unbind 'blur' in cancelValidation() #28

LennyLip opened this issue Apr 19, 2015 · 16 comments

Comments

@LennyLip
Copy link
Contributor

I think, obj.commonObj.elm.unbind('blur'); in cancelValidation() is wrong.

FE, I have a angular-strap tooltip, which triggered on blur event. When i have input field with validation="max_len:50" and empty value when lost focus blur does not work and tooltip does not disappear, because blur is unbind.

@LennyLip LennyLip changed the title unbind 'onBlur' in cancelValidation() unbind 'blur' in cancelValidation() Apr 19, 2015
@ghiscoding
Copy link
Owner

The biggest reason of the cancelValidation() is that I don't want to annoy the user on an empty form, not doing this would mean showing all errors directly at start, which is the reason of the cancelValidation()

You should perhaps try using the checkFormValidity(), that would trigger all the errors while also checking the form validity. If that is not what you are trying to do, then I might have misunderstood your question.

@ghiscoding
Copy link
Owner

Also by the way, the error messages are only showing if the element is $dirty, $touched or if the form has been submitted.

@LennyLip
Copy link
Contributor Author

Ok, i've created http://plnkr.co/edit/x6AI9U8mGF0P4NMVmzvR?p=preview

see second input , tooltip does not disappear, because blur is unbind by cancelValidation(). but in first input all ok, because "required".

@LennyLip
Copy link
Contributor Author

i've beenn updated this comment

@ghiscoding
you wrote "// unbind onBlur event, if not it will fail when input become dirty & empty"

I could be wrong, but may be we can something like: add "watch" and when input empty set $setPristine(); for input.

?

I think unbind 'blur' too radical decision, that affects other modules

ghiscoding added a commit that referenced this issue Apr 21, 2015
- Fixed issue #28 - unbind all 'blur' in cancelValidation() might affect
other modules
@ghiscoding
Copy link
Owner

This should fix it...

@LennyLip
Copy link
Contributor Author

it is does not helped, see http://plnkr.co/edit/x6AI9U8mGF0P4NMVmzvR?p=preview with 1.3.19
may be its angular-strap issue?

@ghiscoding
Copy link
Owner

Well I am not doing a full unbind anymore so I don't think it comes from my end, you could even remove the unbind from my code and it would still work. Try debugging it and see what can cause it... If you want to debug my code, you should use the non-minified versions.

@LennyLip
Copy link
Contributor Author

i h've been commented this line and tooltip is disappeared.

//elm.unbind('blur', blurHandler); // unbind onBlur event so that it does not fail on a non-required element that is now dirty & empty

also, i don't have any "fail on a non-required element that is now dirty & empty" (with dirty & empty input).

@LennyLip
Copy link
Contributor Author

hm, i've been debug
elm.unbind('blur', blurHandler);

and i see, that blurHandler is undefined. (thats why ubnind disable all blur handlers)/

i think, it because cancelValidation() run before elm.bind.

@ghiscoding
Copy link
Owner

it is not suppose to be undefined, it's a global variable and is set at the bind calling, unless it's unset on first pass. You could try commenting out that line (unbind) and see if that really is your problem. I still need to unbind it somehow because I might end up with 50 calls at the end.

@ghiscoding ghiscoding reopened this Apr 21, 2015
@LennyLip
Copy link
Contributor Author

validation-directive.js
we have "elm.bind('blur', blurHandler = function() {" on 85 line, but "cancelValidation();" is call on 72 line in one function "function attemptToValidate(value) {".

so, we call "elm.unbind('blur', blurHandler); " with undefined blurHandler.

http://savepic.net/6756572.png

@LennyLip
Copy link
Contributor Author

You could try commenting out that line (unbind) and see if that really is your problem.

it's really my problem
#28 (comment)

@ghiscoding
Copy link
Owner

Could you try the following

// replace this line
elm.unbind('blur', blurHandler);

// with these lines
if(typeof blurHandler !== "undefined") {
  elm.unbind('blur', blurHandler);
}

I am at work and I cannot really test it, it would help if you can test it with your code too.

@LennyLip
Copy link
Contributor Author

@ghiscoding
seems, it is works, thank you!

@ghiscoding
Copy link
Owner

Ok I will make more tests tonight and will also fix another open issue at the same time. You should expect to see the new code and the minified code on the next version 1.3.20 later tonight.

Thanks

ghiscoding added a commit that referenced this issue Apr 22, 2015
- Added sample of issue #26
- Fixed issue #26 - validation of dynamic forms inside ng-repeat
- Fixed again issue #28 - unbind all 'blur' in cancelValidation() might
affect other modules.
@ghiscoding
Copy link
Owner

As promised, I push the code after testing... Hopefully that works for you

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

2 participants