React-native-modal-datetime-picker: Automatically disabled the before time from current time

Created on 13 Oct 2017  路  12Comments  路  Source: mmazzarolo/react-native-modal-datetime-picker

I am using this module, it's all working fine. I am running a sample app. If i pick a time from the time picker automatically it disables the before time from the current time.

Here is my code:

class ModalDatePicker extends Component {
  constructor(props){
      super(props);
      this.state={
         isTimePickerVisible: false,
         currentTime:moment().format('h:mm a').toUpperCase()
      }
    }
    _showTimePicker = () => this.setState({ isTimePickerVisible: true });

   _hideTimePicker = () => this.setState({ isTimePickerVisible: false });

   _handleTimePicked = (time) => {
     var time = moment(time).format("hh:mm a");
       this.setState({
         currentTime : time.toUpperCase()
       },()=>{
         if(this.state.currentTime < time){
          this.setState({
            currentTime : this.state.currentTime
          })
         }
       })
     this._hideTimePicker();
   };

render(){
      return(
  <View style = {styles.buttonView}>
        <TouchableOpacity onPress={this._showTimePicker}>
        <View style ={styles.pickUpBorderView}>
        <Text>Pickup Time {this.state.currentTime}</Text>
        <DateTimePicker
          isVisible={this.state.isTimePickerVisible}
          onConfirm={this._handleTimePicked}
          onCancel={this._hideTimePicker}
          mode = {'time'}
        />
        </View>
        </TouchableOpacity>
        </View>
)}
}

Here is my screenshot
screen shot 2017-10-13 at 4 18 54 pm
Please give any suggestion for this issue. Thank you

question

Most helpful comment

<DateTimePicker
          isVisible={this.state.isTimePickerVisible}
          onConfirm={this._handleTimePicked}
          is24Hour={true}
          onCancel={this._hideTimePicker}
          mode={'time'}
          minimumDate = {new Date()}
        />

Does this work? It should not allow you to select a date before the current moment

All 12 comments

Hey @harikanammi,
I'm sorry but I can't understand the issue 馃槥
Could you please explain the following sentence a bit more?

it disables the before time from the current time

Thanks!

I want to disabled the completed time in the time picker, thank you for your response

I still don't get it, sorry.
Under the hood react-native-modal-datetime-picker uses react-native original DatePickerAndroid, TimePickerAndroid and DatePickerIOS.
Could you try swapping react-native-datetime-picker with react-native original date/time pickers to check if the problem persists?

I want to disable the previous time in the time picker. It enables only future time in the time picker. Time picker displays only current time to future time.

You should provide the minimumDate to the picker just like you would do with DatePickerIOS.

This is my code.

    <DateTimePicker
      isVisible={this.state.isTimePickerVisible}
      onConfirm={this._handleTimePicked}
      is24Hour = {true}
      onCancel={this._hideTimePicker}
      mode = {'time'}
    />

`` How can i give thisminimumDate` into my code.

<DateTimePicker
      isVisible={this.state.isTimePickerVisible}
      onConfirm={this._handleTimePicked}
      is24Hour = {true}
      minimumDate={your minumum date}
      onCancel={this._hideTimePicker}
      mode = {'time'}
    />
  <DateTimePicker
          isVisible={this.state.isTimePickerVisible}
          onConfirm={this._handleTimePicked}
          is24Hour = {true}
          onCancel={this._hideTimePicker}
          mode = {'time'}
          minimumDate = {this.state.currentTime}
        />

screen shot 2017-10-13 at 7 08 58 pm
I am getting this error.

<DateTimePicker
          isVisible={this.state.isTimePickerVisible}
          onConfirm={this._handleTimePicked}
          is24Hour={true}
          onCancel={this._hideTimePicker}
          mode={'time'}
          minimumDate = {new Date()}
        />

Does this work? It should not allow you to select a date before the current moment

Thank You for your support, it's working

馃憤 have fun!

you might need to tweek it a bit to make it better suit your tastes

I have an issue using this modal i just need date from 1 to 18 date it is showing correct result but after 18 date it start showing me day name and time.

Was this page helpful?
0 / 5 - 0 ratings