kazupon / vue-validator

:white_check_mark: Validator component for Vue.js
MIT License
2.19k stars 431 forks source link

dynamic custom validator #274

Closed szkrd closed 8 years ago

szkrd commented 8 years ago

I'm trying to toggle a custom validator, but it seems to be impossible.

vue & vue-validator version

vue-validator v2.1.3, Vue.js v1.0.26

Reproduction Link

jsFiddle: https://jsfiddle.net/szabi/5ypnz9wg/

Steps to reproduce

enter "cheese" in username input, click "bacon" button, replace text in field with "bacon"

What is Expected?

valid form

What is actually happening?

invalid form

szkrd commented 8 years ago

I could "make it work" with async, but it kinda feels like a hack. https://jsfiddle.net/szabi/Lk9nmfed/2/

nandin-borjigin commented 8 years ago

It seems that when the validatorForUserName variable is changed to ['theBacon'] from ['theCheese'], the former validator is not removed, i.e. there are actually two validators ['theCheese', 'theBacon'] on that input field after that change. This can be observed by adding a line of html <pre> {{ $validation1 | json }} </pre> to @szkrd 's jsfiddle.

@kazupon , I know you're busy developing the 3.0 version, but this may can be solved by adding a few lines of cleaning up code in proper place if my guess is right.

kazupon commented 8 years ago

fixed v2.1.4 https://github.com/vuejs/vue-validator/releases/tag/v2.1.4

woshi82 commented 7 years ago

hi~ @kazupon the same issue still appeared in v3.0.0-alpha.2, i have try the example in https://github.com/kazupon/vue-validator/commit/b5d5487 , but it not work