Skip to content

Commit

Permalink
Working on #7: fixed the selected month in dropdown. Last thing to do…
Browse files Browse the repository at this point in the history
… : fix code when dropdown selection changes :-)
  • Loading branch information
Barbara Post committed Jun 7, 2017
1 parent da25c17 commit 4e6da5b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/ionic-datepicker.bundle.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/ionic-datepicker-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ <h1 class="title">{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.date
<label class="item item-input item-select month_select">
<span class="input-label">&nbsp;</span>
<select ng-model="data.currentMonth" ng-options="select as item.text for item in monthsList track by item.value" ng-change="monthChanged(data.currentMonth)">
<!--<option ng-repeat="month in monthsList | filter:{'!!'}" ng-selected="month == data.currentMonthSelected" value="{{month}}">-->
{{month}}
</option>
</select>
Expand Down
3 changes: 1 addition & 2 deletions src/ionic-datepicker-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<div class="col col-50 padding_right_5px">
<label class="item item-input item-select month_select">
<span class="input-label">&nbsp;</span>
<select ng-model="data.currentMonth" ng-change="monthChanged(data.currentMonth)">
<option ng-repeat="month in monthsList" ng-selected="month==data.currentMonthSelected" value="{{month}}">
<select ng-model="data.currentMonth" ng-options="select as item.text for item in monthsList track by item.value" ng-change="monthChanged(data.currentMonth)">
{{month}}
</option>
</select>
Expand Down
17 changes: 13 additions & 4 deletions src/ionic-datepicker.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ angular.module('ionic-datepicker.provider', [])
}

$scope.currentDate = newDate;
$scope.data.currentMonth = $scope.monthsNames[$scope.currentDate.getMonth()];
$scope.data.currentMonth = findMonth($scope.currentDate.getMonth(), $scope.monthsList);
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);
Expand All @@ -88,12 +88,21 @@ angular.module('ionic-datepicker.provider', [])
}

$scope.currentDate = newDate;
$scope.data.currentMonth = $scope.monthsNames[$scope.currentDate.getMonth()];
$scope.data.currentMonth = findMonth($scope.currentDate.getMonth(), $scope.monthsList);
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);
};

var findMonth = function(monthId, scopeMonthList) {
for(var i = 0; i < scopeMonthList.length; i++) {
if(scopeMonthList[i].value === monthId) {
return scopeMonthList[i];
}
}
return scopeMonthList[0];
};

//Get the acceptable day
var getAcceptableDay = function(currentDay, newMonth, newYear) {
var nbDaysInMonth = new Date(newYear, newMonth+1, 0).getDate();
Expand Down Expand Up @@ -223,7 +232,7 @@ angular.module('ionic-datepicker.provider', [])
$scope.rows = [0, 7, 14, 21, 28, 35];
$scope.cols = [0, 1, 2, 3, 4, 5, 6];

$scope.data.currentMonth = $scope.monthsNames[currentDate.getMonth()];
$scope.data.currentMonth = findMonth($scope.currentDate.getMonth(), $scope.monthsList);
$scope.data.currentYear = currentDate.getFullYear();
$scope.data.currentMonthSelected = angular.copy($scope.data.currentMonth);
$scope.currentYearSelected = angular.copy($scope.data.currentYear);
Expand All @@ -232,7 +241,7 @@ angular.module('ionic-datepicker.provider', [])

//Month changed
$scope.monthChanged = function (month) {
var monthNumber = $scope.monthsNames.indexOf(month);
var monthNumber = month;
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
monthNumber,
Expand Down
1 change: 0 additions & 1 deletion src/ionic-datepicker.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ angular.module('ionic-datepicker.service', [])
return yearsList;
};

// 12 items, not available months are null
// item has "value" and "text" json keys
this.getMonthsList = function (monthNames, from, to) {
var monthsList = [];
Expand Down

0 comments on commit 4e6da5b

Please sign in to comment.