Skip to content

Commit e6011f2

Browse files
committed
fixes #28 and on Blank input open current date will not be selected
1 parent 1af61a5 commit e6011f2

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

projects/ionic4-datepicker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@logisticinfotech/ionic4-datepicker",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "ionic4-datepicker inspired by rajeshwar patlolla ionic1 datepicker",
55
"keywords": ["Ionic-datepicker", "ionic", "ionic datepicker", "datepicker", "datepicker ionic", "datepicker for ionic", "datepicker for ionic framework"],
66
"license": "SEE LICENSE IN LICENSE",

projects/ionic4-datepicker/src/lib/ionic4-datepicker-modal/ionic4-datepicker-modal.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ <h1 *ngIf="mainObj?.titleLabel">{{mainObj?.titleLabel}}</h1>
9090
</ion-button>
9191
</ion-col>
9292
<ion-col no-padding *ngIf="!mainObj?.closeOnSelect">
93-
<ion-button class="ion-button" expand="{{mainObj?.btnProperties?.expand}}" fill="{{mainObj?.btnProperties?.fill}}"
94-
size="{{mainObj?.btnProperties?.size}}" color="{{mainObj?.btnProperties?.color}}" disabled="{{mainObj?.btnProperties?.disabled}}"
93+
<ion-button class="ion-button" expand="{{mainObj?.btnProperties?.expand}}"
94+
fill="{{mainObj?.btnProperties?.fill}}" size="{{mainObj?.btnProperties?.size}}"
95+
color="{{mainObj?.btnProperties?.color}}"
96+
disabled="{{mainObj?.btnProperties?.disabled || !isSelectedDateFound}}"
9597
strong="{{mainObj?.btnProperties?.strong}}" (click)="setIonicDatePickerDate()">
9698
{{mainObj?.setLabel}}
9799
</ion-button>

projects/ionic4-datepicker/src/lib/ionic4-datepicker-modal/ionic4-datepicker-modal.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Ionic4DatepickerModalComponent implements OnInit {
2121
selectedDate: any = {};
2222

2323
// component variables
24-
selctedDateEpoch;
24+
selctedDateEpoch = 0;
2525
firstDayEpoch;
2626
lastDayEpoch;
2727

@@ -55,6 +55,8 @@ export class Ionic4DatepickerModalComponent implements OnInit {
5555
isMonthSelect;
5656
scrollingMonthOrYearArray: any = [];
5757

58+
isSelectedDateFound = false;
59+
5860
constructor(
5961
private navParams: NavParams,
6062
private modalCtrl: ModalController
@@ -63,6 +65,7 @@ export class Ionic4DatepickerModalComponent implements OnInit {
6365
if (this.navParams.get('selectedDate')) {
6466
// console.log('Selected date =>', this.navParams.get('selectedDate'));
6567
this.selectedDate.date = this.navParams.get('selectedDate');
68+
this.isSelectedDateFound = true;
6669
}
6770
this.mainObj = this.initDatePickerObj(this.navParams.get('objConfig'));
6871
}
@@ -178,6 +181,7 @@ export class Ionic4DatepickerModalComponent implements OnInit {
178181
// console.log('dateSelected =>', selectedDate);
179182
if (selectedDate && !selectedDate.disabled) {
180183
if (!selectedDate || Object.keys(selectedDate).length === 0) { return; }
184+
this.isSelectedDateFound = true;
181185
this.selctedDateEpoch = selectedDate.epoch;
182186
this.selectedDateString = this.formatDate();
183187
if (this.mainObj.closeOnSelect) {
@@ -320,8 +324,13 @@ export class Ionic4DatepickerModalComponent implements OnInit {
320324
setInitialObj(ipObj) {
321325
// console.log('setInitialObj =>', ipObj);
322326
this.mainObj = ipObj;
323-
this.selctedDateEpoch = this.resetHMSM(this.mainObj.inputDate).getTime();
327+
if (this.isSelectedDateFound) {
328+
this.isSelectedDateFound = true;
329+
this.selctedDateEpoch = this.resetHMSM(this.mainObj.inputDate).getTime();
330+
}
331+
324332
this.selectedDateString = this.formatDate();
333+
325334
if (this.mainObj.weeksList && this.mainObj.weeksList.length === 7) {
326335
this.weeksList = this.mainObj.weeksList;
327336
}

projects/ionic4-datepicker/src/lib/li-ionic4-datepicker.directive.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class LiIonic4DatepickerDirective implements OnInit {
1818

1919
closeIcon;
2020
selectedDate: any = {};
21-
isModalOpen: any = false;
21+
// isModalOpen: any = false;
2222

2323
constructor(
2424
private modalCtrl: ModalController,
@@ -95,13 +95,13 @@ export class LiIonic4DatepickerDirective implements OnInit {
9595

9696
@HostListener('ionFocus')
9797
onFocus() {
98-
// console.log('on focus of component =>', this.inputDateConfig);
99-
if (!this.isModalOpen) {
100-
this.isModalOpen = true;
101-
this.openDatePicker();
102-
}
98+
// if (!this.isModalOpen) {
99+
// this.isModalOpen = true;
100+
this.openDatePicker();
101+
// }
103102
}
104103

104+
105105
async openDatePicker() {
106106
// console.log('openDatePicker');
107107

@@ -114,8 +114,7 @@ export class LiIonic4DatepickerDirective implements OnInit {
114114

115115
datePickerModal.onDidDismiss()
116116
.then((data) => {
117-
this.isModalOpen = false;
118-
// console.log(data);
117+
// this.isModalOpen = false;
119118
if (data.data && data.data.date && data.data.date !== 'Invalid date') {
120119
this.selectedDate.date = data.data.date;
121120
this.control.control.setValue(data.data.date);

0 commit comments

Comments
 (0)