kazupon / vue-validator

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

Is multiple validators under same vm supported? #220

Closed xjchengo closed 8 years ago

xjchengo commented 8 years ago

Currently, we can define multiple validators with different names under same vm. In most case, this works well except when calls $resetValidation(), $activateValidator() etc. These methods just work on last validator. If multiple validators under same vm need to be supported, these methods should add a param indicating which validator it works on.

kazupon commented 8 years ago

Thank you feedback!! Yeah!! You're right 😃 We need to support these methods ($resetValidation(), $validate(), etc,).

xjchengo commented 8 years ago

@kazupon I have written some code to improve these methods. But I am stuck with debug and unit test. How to debug the plugin during development? npm run dev throws:

ERROR in multi main
Module not found: Error: Cannot resolve 'file' or 'directory' ./index.js in /home/vagrant/Projects/vuejs-vue-validator
 @ multi main

When I run npm run dev-test in Windows 8 and open the test page in browser, console shows:

.*$:31 Uncaught Error: Cannot find module './sinon/util/core'.

and some esline errors:

C:\Users\Xujian\Projects\xjchengo-vue-validator\test\specs\validators.js
  171:38  error  Unnecessary escape character: \'  no-useless-escape
  177:38  error  Unnecessary escape character: \"  no-useless-escape

In ubuntu, sinon works fine. But all top level event related tests failed with:.

Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
    at eval (eval at <anonymous> (specs.js:8427:9), <anonymous>:4190:19)

I found that handler.apply at https://github.com/vuejs/vue-validator/blob/dev/src/validator.js#L384 just return the event handler. Handler must be applied twice to make it executed.

Can you give me some tips to solve these problem? Thanks.

kazupon commented 8 years ago

npm run dev

I use the to develop feature driven (prototype browser base) development. I recommend that you develop with using the npm run dev-test or npm run unit.

When I run npm run dev-test in Windows 8 and open the test page in browser, console shows:

I have not been able to confirm whether it is possible development at windows yet. if you want to develop soon, I recommend that you develop with using vagrant or docker at the OS like the UNIX environment.

and some esline errors: C:\Users\Xujian\Projects\xjchengo-vue-validator\test\specs\validators.js 171:38 error Unnecessary escape character: \' no-useless-escape 177:38 error Unnecessary escape character: \" no-useless-escape

and

But all top level event related tests failed with:. Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. at eval (eval at (specs.js:8427:9), :4190:19) I found that handler.apply at https://github.com/vuejs/vue-validator/blob/dev/src/validator.js#L384 just return the event handler. Handler must be applied twice to make it executed.

I'll try to check the later.

Thanks!!

xjchengo commented 8 years ago

In Mac OS X, there is no eslint error and all test are passed.

kazupon commented 8 years ago

I'll try to implement at v3.0.

Jamiek94 commented 8 years ago

@kazupon Is there a workaround to manually validate a specific validator?

kazupon commented 8 years ago

released v3.0.0-alpha.1 https://github.com/vuejs/vue-validator/releases/tag/v3.0.0-alpha.1

In 3.0 later, valuable method (validate, reset, etc...) is scoped with validity component.