How to use the react-dates/lib/utils/toMomentObject function in react-dates

To help you get started, we’ve selected a few react-dates examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awethemes / awebooking / assets / babel / calendar.jsx View on Github external
onStartDateChange(e) {
    let startDateString = e.target.value

    let { endDate } = this.state
    const { disabled, minimumNights, isOutsideRange } = this.props

    const startDate = toMomentObject(startDateString, this.getDisplayFormat())
    console.log(startDate)

    const isEndDateBeforeStartDate = startDate
      && isBeforeDay(endDate, startDate.clone().add(minimumNights, 'days'))

    const isStartDateValid = startDate
      && !isOutsideRange(startDate)
      && !(disabled === END_DATE && isEndDateBeforeStartDate)

    if (isStartDateValid) {
      if (isEndDateBeforeStartDate) {
        endDate = null
      }

      this.onDatesChange({ startDate, endDate })
      this.onFocusChange(END_DATE)
github awethemes / awebooking / assets / babel / search-form / SearchForm.js View on Github external
      ? disableDates.split(/,\s?/).map(day => toMomentObject(day))
      : disableDates
github awethemes / awebooking / assets / babel / calendar.jsx View on Github external
onEndDateChange(e) {
    const endDateString = e.target.value

    const { startDate } = this.state
    const { minimumNights, isOutsideRange, keepOpenOnDateSelect } = this.props

    const endDate = toMomentObject(endDateString, this.getDisplayFormat())

    const isEndDateValid = endDate
      && !isOutsideRange(endDate)
      && !(startDate && isBeforeDay(endDate, startDate.clone().add(minimumNights, 'days')))

    if (isEndDateValid) {
      this.onDatesChange({ startDate, endDate })
      if (!keepOpenOnDateSelect) this.onClearFocus()
    } else {
      this.onDatesChange({
        startDate,
        endDate: null,
      })
    }
  }
github awethemes / awebooking / assets / babel / calendar.jsx View on Github external
constructor(props) {
    super(props)

    if (typeof window.Popper === 'undefined') {
      throw new TypeError('The Calendar require Popper.js (https://popper.js.org/)')
    }

    this.form = props.form
    const { elements } = this.form

    this.state = {
      focusedInput: null,
      startDate: toMomentObject(elements['check_in'].get()),
      endDate: toMomentObject(elements['check_out'].get()),
      isDayPickerFocused: false,
    }

    this.onDatesChange = this.onDatesChange.bind(this)
    this.onFocusChange = this.onFocusChange.bind(this)
    this.onOutsideClick = this.onOutsideClick.bind(this)
    this.onDayPickerBlur = this.onDayPickerBlur.bind(this)
    this.isOutsideRange = this.isOutsideRange.bind(this)
  }
github awethemes / awebooking / assets / babel / calendar.jsx View on Github external
constructor(props) {
    super(props)

    if (typeof window.Popper === 'undefined') {
      throw new TypeError('The Calendar require Popper.js (https://popper.js.org/)')
    }

    this.form = props.form
    const { elements } = this.form

    this.state = {
      focusedInput: null,
      startDate: toMomentObject(elements['check_in'].get()),
      endDate: toMomentObject(elements['check_out'].get()),
      isDayPickerFocused: false,
    }

    this.onDatesChange = this.onDatesChange.bind(this)
    this.onFocusChange = this.onFocusChange.bind(this)
    this.onOutsideClick = this.onOutsideClick.bind(this)
    this.onDayPickerBlur = this.onDayPickerBlur.bind(this)
    this.isOutsideRange = this.isOutsideRange.bind(this)
  }