ember-power-calendar
ember-power-calendar copied to clipboard
How to enable only change start date in power calendar range component, end date will be fixed
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);
}
}