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

nuzhy/datepicker min date config issue #770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/javascript/app/pages/form/form-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ export const FormComponent = () => {
return null;
}

const getMinMaxDate = () => {
const { minDate: min, maxDate: max } = endtime_data.datepicker_config;
const today = new Date();

const minDate = new Date(today);
minDate.setDate(today.getDate() + min);

const maxDate = new Date(today);
maxDate.setDate(today.getDate() + max);

return { minDate, maxDate };
};

const payoutTypeOptions = [
{ text: localize('Stake'), value: 'stake' },
{ text: localize('Payout'), value: 'payout' },
Expand Down Expand Up @@ -222,7 +235,10 @@ export const FormComponent = () => {
{endtime_data.show_datepicker ? (
<DatePickerDropdown
value={moment(expiry_date).format('DD/MM/YYYY')}
datePickerProps={{ minDate: new Date() }}
datePickerProps={{
minDate: getMinMaxDate().minDate,
maxDate: getMinMaxDate().maxDate,
}}
onSelectDate={(value) => {
onExpiryDateChange(value);
}}
Expand Down
7 changes: 5 additions & 2 deletions src/javascript/app/pages/trade/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@ const Durations = (() => {
const changeExpiryTimeType = () => {
let requested = -1;
const endtime_data = {
options : [],
show_datepicker: true,
options : [],
show_datepicker : true,
datepicker_config: {},
};
if (CommonFunctions.getElementById('expiry_type').value === 'endtime') {
let $expiry_date = $('#expiry_date');
Expand All @@ -400,6 +401,8 @@ const Durations = (() => {
});
endtime_data.options = [];
endtime_data.show_datepicker = true;
endtime_data.datepicker_config.minDate = smallest_duration.unit === 'd' ? 1 : 0;
endtime_data.datepicker_config.maxDate = 365;
} else {
endtime_data.options = [];
endtime_data.show_datepicker = false;
Expand Down
Loading