Vee-validate: How to use Vue js data variables value in as parameter

Created on 21 Mar 2017  路  5Comments  路  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.1
  • Vee-Validate:

Description:

How to use Vue js data variables value in as parameter?
<input type="text" :value="totalWeek1" name="totalWeek1" v-validate="'between:min,max'"/>
data:{ min:5, max:10 }

Most helpful comment

this worked for me
<input v-validate="'required|min_value:1|max_value:' + months">

where

data () 
  return {
    months: 12
  }

All 5 comments

I have found a trick
<input type="text" :value="totalWeek1" name="totalWeek1" v-validate="validation"/>

data:{ validation:'', min:5, max:10, }
` mounted: function()
{
this.validation='between:'+this.min+','+this.max;

},`

This is not a beautiful code but it works. Someone for a best solution?

If you are using ES6, you can use template string for this:

<input type="text" :value="totalWeek1" name="totalWeek1" v-validate="`between:${min},${max}`"/>

This is not working. I get:
The totalWeek1 field must be between ${min} and ${max}.
I I'm using ES6 (using Laravel 5.4)

The browser must be capable of ES6, unless you use vue-loader which should convert it with babel for you.

https://jsfiddle.net/logaretm/wu8uoryk/

this worked for me
<input v-validate="'required|min_value:1|max_value:' + months">

where

data () 
  return {
    months: 12
  }
Was this page helpful?
0 / 5 - 0 ratings