What is the cause of [Vue warn]: Invalid prop: custom validator check failed for prop "value"

by Andrey Khataev   Last Updated May 16, 2019 00:26 AM

I have nuxt.js app, which uses vuejs-datepicker:

<template>
<!-- ... -->

    <DatePicker :value="datePicker.value" />
 <!-- ... -->
 </template>

and bunch of date variables:

<script>
import DatePicker from 'vuejs-datepicker'
import { DateTime } from 'luxon'

const moment = require('moment')

const date = new Date(2016, 8, 16)
const date2 = moment('2016-09-16').toDate()
const date3 = DateTime.local(2016, 9, 16).toJSDate()

export default {
  components: {
    DatePicker
  },
  data() {
    return {
      datePicker: {
        mondayFirst: true,
        format: 'dd.MM.yyyy',
        value: date
      }
    }
  }
}

When I bind its 'value' property to usual Date variable 'date', everything is ok, but when I choose date2 or date3, I get this annoying warning

[Vue warn]: Invalid prop: custom validator check failed for prop "value".

found in

---> <DatePicker>
       <StaticPositionsTab> at components/StaticPositions.vue
         <BTab>
           <BTabs>
             <Pages/index.vue> at pages/index.vue
               <Nuxt>
                 <Layouts/default.vue> at layouts/default.vue
                   <Root>

I found custom validator for value property and it is very straightforward and simple and return true in all three cases:

value: {
      validator: function (val) { return utils$1.validateDateInput(val); }
    }

...

validateDateInput (val) {
    return val === null || val instanceof Date || typeof val === 'string' || typeof val === 'number'
  }

but what makes the difference then? Could it be Vue.js bug itself?



Answers 1


date2 and date3 are object, while value requires null | Date | string | number

const date2 = moment('2016-09-16').toDate()
const date3 = DateTime.local(2016, 9, 16).toJSDate()

typeof date2 // object
typeof date3 // object

You should use .toString() to convert them to string

const date2 = moment('2016-09-16').toString()
const date2 = moment('2016-09-16').toISOString()
const date3 = DateTime.local(2016, 9, 16).toString()
ittus
ittus
May 16, 2019 00:24 AM

Related Questions


Updated November 14, 2017 08:26 AM

Updated December 16, 2018 23:26 PM

Updated February 24, 2019 18:26 PM

Updated September 30, 2018 00:26 AM

Updated December 11, 2018 19:26 PM