Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable only change start date in power calendar range component, end date will be fixed #247

Open
aman0511 opened this issue Mar 12, 2020 · 1 comment

Comments

@aman0511
Copy link

No description provided.

@christophermlne
Copy link

christophermlne commented Jul 14, 2020

this is not possible through the public api - you will have to override the component.

this is how i pinned the start date. you have to pass proximitySelection=true to the datepicker. you would have to do something similar to pin the end date:

// app/components/power-calendar-range.js

import CalendarRangeComponent from 'ember-power-calendar/components/power-calendar-range';
import {
  normalizeRangeActionValue,
  diff,
  isBefore,
} from 'ember-power-calendar-utils';

export default class extends CalendarRangeComponent {
  /**
   *  We have to override this private method in order to pin the
   *  start date in proximity mode by allowing the component to accept an additional
   *  parameter, `startDateLocked`.
   */
  _buildRangeByProximity(day, start, end) {
    if (start && end) {
      let changeStart;

      if (this.startDateLocked) {
        changeStart = false;
      } else {
        changeStart = Math.abs(diff(day.date, end)) > Math.abs(diff(day.date, start));
      }

      return normalizeRangeActionValue({
        date: {
          start: changeStart ? day.date : start,
          end: changeStart ? end : day.date,
        },
      });
    }

    if (isBefore(day.date, start)) {
      return normalizeRangeActionValue({ date: { start: day.date, end: null } });
    }

    return this._buildDefaultRange(day, start, end);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants