Element: value.getTime() not a function

Created on 2 Mar 2017  ·  5Comments  ·  Source: ElemeFE/element

<el-form-item required prop="end_time">
 <el-date-picker
      v-model="event.end_time"
       type="datetime"
       style="width: 100%;"
       placeholder="Select end time">
   </el-date-picker>
</el-form-item>
 import {
        DatePicker,
        TimePicker,
    } from 'element-ui'

    export default{

        components: {
            'el-date-picker': DatePicker,
            'el-time-picker': TimePicker,
        },

 data () {
            return {
                rules: {

                    start_time: [
                        { required: true, type:'date', message: 'Please pick a time', trigger: 'change' },
                    ],
                    end_time: [
                        { required: true, type:'date', message: 'Please pick a time', trigger: 'change' },
                    ],
                }
            }

Vuejs 2.2.1
Element UI : 1.2.3

I've got this error when validating my form.

value.getTime() not a function

Here is the bugged line in the Chome console :

if (value) {
        _rule2["default"].range(rule, value.getTime(), source, errors, options);
      }

My value = "2017-03-23 23:00:00"

What can I do ? Thank you

Most helpful comment

All U need to do is change the type in the rules to "string". That's it!

All 5 comments

because the data of time is a string ,not a object Date or js timestamp

https://jsfiddle.net/1tqrt0p6/

Both String and Date type are supported.

我也遇见了这样的问题,于是我选择了自定义校验,规避了这个

All U need to do is change the type in the rules to "string". That's it!

make sure that you have validation for the field on your server side

Was this page helpful?
0 / 5 - 0 ratings