Vuelidate example
HTML
<script src="https://unpkg.com/vuelidate/dist/vuelidate.min.js"></script>
<script src="https://unpkg.com/vuelidate/dist/validators.min.js"></script>
<div id="app">
<input v-model="$v.faith.$model" :class="status($v.faith)">
<pre>{{ $v }}</pre>
</div>
CSS
input {
border: 1px solid silver;
border-radius: 4px;
background: white;
padding: 5px 10px;
}
.dirty {
border-color: #5A5;
background: #EFE;
}
.dirty:focus {
outline-color: #8E8;
}
.error {
border-color: red;
background: #FDD;
}
.error:focus {
outline-color: #F99;
}
Babel + JSX
Vue.use(window.vuelidate.default)
const { alpha, maxLength, requiredIf } = window.validators
new Vue({
el: "#app",
data: {
faith: '',
ch_class: 'Paladin'
},
validations () {
return {
faith: {
requiredIf: requiredIf(() => {
return this.ch_class == 'Paladin'|| this.ch_class == 'Druid'|| this.ch_class == 'Cleric'
}),
alpha,
maxLength: maxLength(25)
}
}
},
methods: {
status(validation) {
return {
error: validation.$error,
dirty: validation.$dirty
}
}
}
})