Ed Lynch
Ed Lynch

Reputation: 623

Can't get the value from rc-time-picker

Basically this:

        <TimePicker
        id="startTime"
        showSecond={false}
        defaultValue={now}
        className="xxx"
        onChange={function(){
          console.log(this.value);
        }}
        format={format}
        use12Hours
        disabled={dateBlocked}
        name="startTime"
        />

is logging:

undefined

to the console. Why not it's date as a moment?

This

console.log(this.defaultValue);

Works fine.

Upvotes: 0

Views: 2162

Answers (1)

btzr
btzr

Reputation: 2154

Value

The timePicker's value it's provide as an argument by theOnChange event.

It should be:

 onChange={ function(value){console.log(value)} }

Example

// Display seconds
const showSecond = true;

//Format string
const str = showSecond ? 'HH:mm:ss' : 'HH:mm';

//Handle onChange event
function handleChange(value) {
    console.log(value && value.format(str));
}
...
onChange={handleChange}

github/example/picktime.js

Upvotes: 1

Related Questions