Last active
April 17, 2017 13:12
-
-
Save hectorgool/40117d1c6f0e76d5cc602ee5918f5377 to your computer and use it in GitHub Desktop.
vee validation test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Vue.js Tutorial | API Example</title> | |
| <!-- Latest compiled and minified CSS --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
| <!-- Optional theme --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | |
| </head> | |
| <body> | |
| <div id="app"> | |
| <div class="container"> | |
| <form> | |
| <div class="form-group" :class="{'has-error': errors.has('email') }" > | |
| <label class="control-label" for="email">Email</label> | |
| <input v-model="email" v-validate="email" data-rules="required|email" class="form-control" type="email" placeholder="Email"> | |
| <p class="text-danger" v-if="errors.has('email')">{{ errors.first('email') }}</p> | |
| </div> | |
| <button type="submit" class="btn btn-default">Submit</button> | |
| </form> | |
| </div> <!-- end of .container --> | |
| </div> <!-- end of #app --> | |
| <!-- Latest compiled and minified JavaScript --> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/vee-validate/2.0.0-beta.25/vee-validate.min.js"></script> | |
| <script> | |
| Vue.use(VeeValidate); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Vue.js Tutorial | API Example</title> | |
| <!-- Latest compiled and minified CSS --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
| <!-- Optional theme --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | |
| </head> | |
| <body> | |
| <div id="app"> | |
| <div class="container"> | |
| <form @submit.prevent="validateBeforeSubmit"> | |
| <div class="column is-12"> | |
| <label class="label">Email</label> | |
| <p class="control has-icon has-icon-right"> | |
| <input name="email" v-model="email" v-validate:email.initial="'required|email'" :class="{'input': true, 'is-danger': errors.has('email') }" type="text" placeholder="Email"> | |
| <i v-show="errors.has('email')" class="fa fa-warning"></i> | |
| <span v-show="errors.has('email')" class="help is-danger">{{ errors.first('email') }}</span> | |
| </p> | |
| </div> | |
| <div class="column is-12"> | |
| <label class="label">Name</label> | |
| <p class="control has-icon has-icon-right"> | |
| <input name="name" v-model="name" v-validate:name.initial="'required|alpha'" :class="{'input': true, 'is-danger': errors.has('name') }" type="text" placeholder="Name"> | |
| <i v-show="errors.has('name')" class="fa fa-warning"></i> | |
| <span v-show="errors.has('name')" class="help is-danger">{{ errors.first('name') }}</span> | |
| </p> | |
| </div> | |
| <div class="column is-12"> | |
| <label class="label">Phone</label> | |
| <p class="control has-icon has-icon-right"> | |
| <input name="phone" v-model="phone" v-validate:phone.initial="'required|numeric'" :class="{'input': true, 'is-danger': errors.has('phone') }" type="text" placeholder="Phone"> | |
| <i v-show="errors.has('phone')" class="fa fa-warning"></i> | |
| <span v-show="errors.has('phone')" class="help is-danger">{{ errors.first('phone') }}</span> | |
| </p> | |
| </div> | |
| <div class="column is-12"> | |
| <label class="label">Website</label> | |
| <p class="control has-icon has-icon-right"> | |
| <input name="url" v-model="url" v-validate:url.initial="'required|url'" :class="{'input': true, 'is-danger': errors.has('url') }" type="text" placeholder="Website"> | |
| <i v-show="errors.has('url')" class="fa fa-warning"></i> | |
| <span v-show="errors.has('url')" class="help is-danger">{{ errors.first('url') }}</span> | |
| </p> | |
| </div> | |
| <div class="column is-12"> | |
| <p class="control"> | |
| <button class="button is-primary" type="submit">Submit</button> | |
| </p> | |
| </div> | |
| </form> | |
| </div> <!-- end of .container --> | |
| </div> <!-- end of #app --> | |
| <!-- Latest compiled and minified JavaScript --> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/vee-validate/2.0.0-beta.25/vee-validate.min.js"></script> | |
| <script> | |
| Vue.use(VeeValidate); | |
| new Vue({ | |
| name: 'form-example', | |
| data: () => ({ | |
| email: '', | |
| name: '', | |
| phone: '', | |
| url: '' | |
| }), | |
| methods: { | |
| validateBeforeSubmit() { | |
| this.$validator.validateAll().then(() => { | |
| // eslint-disable-next-line | |
| console.log('From Submitted!'); | |
| }).catch(() => { | |
| // eslint-disable-next-line | |
| console.log('Correct them errors!'); | |
| }); | |
| } | |
| } | |
| }).$mount('#app'); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment