time-picker icon indicating copy to clipboard operation
time-picker copied to clipboard

defaultValue props bug

Open Mujaddadi opened this issue 7 years ago • 12 comments

There is a weird bug in the time picker. When I give some formatted moment object to default prop, the on change handler returns the default value not the changed value. For example if the default value is moment(this.props.defaultValue).format('YYYY-MM-DD') and we changed the date in timepicker, it changes the display date in time picker but returns the default time provided .

defaultValue={moment(this.props.defaultValue).format('YYYY-MM-DD')} onChange = value => { console.log(value) }

Mujaddadi avatar Nov 27 '17 14:11 Mujaddadi

You should use value to control the component.

https://facebook.github.io/react/docs/forms.html#controlled-components

afc163 avatar Nov 27 '17 14:11 afc163

That also doesn't work

class CustomTimePickerModal extends React.Component {

    constructor(props){
      super(props);
      this.state = { value: this.props.defaultValue };
    }
  onChange = value => {
      this.setState({ value: value });
      this.props.onChange(value)
  }


  render() {
    return (
      <div className={styles.timepicker}>
        <TimePicker  showSecond={false} onChange={this.onChange}  clearText={'Close the Picker'} value={this.state.value} placeholder={`${moment().format('hh:mm')}` || `${moment().format('hh:mm')}`} />
      </div>
    );
  }
}

Mujaddadi avatar Nov 27 '17 15:11 Mujaddadi

The value should be a moment instance but moment().format('xx') is not one.

afc163 avatar Nov 27 '17 15:11 afc163

That's how I am passing the value to the custom component defaultValue={moment(task.realizedStartTime)}

Mujaddadi avatar Nov 27 '17 15:11 Mujaddadi

That's the moment object which is created

s

Mujaddadi avatar Nov 27 '17 15:11 Mujaddadi

That formated value was passed to placeholder prop not to value placeholder={${moment().format('hh:mm')}||${moment().format('hh:mm')}}

Mujaddadi avatar Nov 27 '17 15:11 Mujaddadi

Could you provide a reproducible demo by forking this: https://codesandbox.io/s/mrq288569 ?

afc163 avatar Nov 27 '17 15:11 afc163

Here is it https://codesandbox.io/s/zqww68629p

As you can check it doesn't return the correct value in the console.

Mujaddadi avatar Nov 27 '17 15:11 Mujaddadi

I think the issue was probably related to call back as I am getting the correct value in the component call back who is using the date picker.

Mujaddadi avatar Nov 27 '17 17:11 Mujaddadi

@Mujaddadi I am facing same problem. did you fix this one?

Rainpia avatar Nov 25 '19 07:11 Rainpia

@Rainpia I started using some other date picker. As you can see this issue is almost 2 years old and still open, I don't have hope that the developer has time to fix it.

Mujaddadi avatar Nov 26 '19 17:11 Mujaddadi

For me using moment(offStartTime, 'HH:mm') instead of moment(offStartTime).format('HH:mm') did the trick

mirceaciu avatar Dec 21 '21 17:12 mirceaciu