Skip to content

Commit

Permalink
fixed hideDefaultValue to hide onChange call for first time
Browse files Browse the repository at this point in the history
  • Loading branch information
sbmdkl committed Sep 25, 2021
1 parent 4605c41 commit 32f2053
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
41 changes: 25 additions & 16 deletions src/components/Calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,25 @@ class Calendar extends Component {
minDate: '',
maxDate: '',
defaultDate: '',
hideDefaultValue: false,
};

state = {
currentMonth,
currentYear,
currentDay: 1,
dates: [],
showCalendar: false,
selectedDate: '',
today: '',
language: 'NE',
theme: 'default',
hideDefaultValue: this.props.hideDefaultValue,
};

wrapperRef = React.createRef();
inputRef = React.createRef();

componentDidMount() {
let { currentYear, currentMonth, currentDay } = adToBs();
const language = this.validateLanguage(this.props.language);
Expand Down Expand Up @@ -61,13 +76,20 @@ class Calendar extends Component {
theme,
},
() => {
this.props.onChange(
if (this.state.hideDefaultValue)
this.formatDate(
language === 'NE'
? convertFullDateToNepali(currentYear + '-' + currentMonth + '-' + currentDay)
: getFullEnglishDate(currentYear + '-' + currentMonth + '-' + currentDay)
)
);
);
else
this.props.onChange(
this.formatDate(
language === 'NE'
? convertFullDateToNepali(currentYear + '-' + currentMonth + '-' + currentDay)
: getFullEnglishDate(currentYear + '-' + currentMonth + '-' + currentDay)
)
);
}
);
document.addEventListener('mousedown', this.handleClickOutside);
Expand All @@ -87,19 +109,6 @@ class Calendar extends Component {
}
};

state = {
currentMonth,
currentYear,
currentDay: 1,
dates: [],
showCalendar: false,
selectedDate: '',
today: '',
language: 'NE',
theme: 'default',
hideDefaultValue: this.props.hideDefaultValue || false,
};

validateTheme = (th) => {
let theme = th || 'default';
theme = theme.toString().toLowerCase();
Expand Down
1 change: 0 additions & 1 deletion src/utils/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ const getFormattedDay = (language, length, index) => {
}
};
const getFormattedMonth = (language, index) => {
console.log(index);
if (language === 'NE') {
index = getEnglishNumber(index);
index--;
Expand Down

0 comments on commit 32f2053

Please sign in to comment.