Skip to content

Commit

Permalink
New setOnSelect property
Browse files Browse the repository at this point in the history
Closes #137
  • Loading branch information
indrimuska committed Mar 18, 2017
1 parent d224fdb commit e665cd6
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ position | | Sets a fixed position for the picker. Available values are `"top le
inline | `false` | Views the picker inline. | [Plunker](https://embed.plnkr.co/5PhKOc)
validate | `true` | Forces picker value between the range `minDate` and `maxDate`. | [Plunker](https://embed.plnkr.co/hFTyMV)
autoclose | `true` | Closes the picker after selecting a date. | [Plunker](https://embed.plnkr.co/z7M6WK)
set-on-select | `false` | Updates picker model after selecting a date in each view. | [Plunker](https://embed.plnkr.co/hJRNcT)
is-open | | Open/closes the picker when set to `true` or `false`. | [Plunker](https://embed.plnkr.co/7T4sbs)
today | `false` | Highlights the current day. | [Plunker](https://embed.plnkr.co/YYbV4C)
keyboard | `false` | Allows using the keyboard to navigate the picker. | [Plunker](https://embed.plnkr.co/OdUhHx)
Expand Down Expand Up @@ -159,6 +160,7 @@ position | | Sets a fixed position for the picker. Available values are `"top le
inline | `false` | Views the picker inline.
validate | `true` | Forces picker value between the range `minDate` and `maxDate`.
autoclose | `true` | Closes the picker after selecting a date.
set-on-select | `false` | Updates picker model after selecting a date in each view.
today | `false` | Highlights the current day.
keyboard | `false` | Allows using the keyboard to navigate the picker.
show-header | `true` | Shows the header in the view.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-moment-picker",
"version": "0.9.9",
"version": "0.9.10",
"authors": [
"Indri Muska <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-moment-picker.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Angular Moment Picker - v0.9.9 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */
/*! Angular Moment Picker - v0.9.10 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */
.moment-picker {
position: relative;
display: block;
Expand Down
14 changes: 11 additions & 3 deletions dist/angular-moment-picker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Angular Moment Picker - v0.9.9 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */
/*! Angular Moment Picker - v0.9.10 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
Expand Down Expand Up @@ -93,6 +93,7 @@
inline: false,
validate: true,
autoclose: true,
setOnSelect: false,
today: false,
keyboard: false,
showHeader: true,
Expand Down Expand Up @@ -173,6 +174,7 @@
inline: '@?',
validate: '=?',
autoclose: '=?',
setOnSelect: '=?',
isOpen: '=?',
today: '=?',
keyboard: '=?',
Expand All @@ -185,7 +187,7 @@
$transclude(function ($transElement) {
// one-way binding attributes
angular.forEach([
'locale', 'format', 'minView', 'maxView', 'startView', 'position', 'inline', 'validate', 'autoclose', 'today',
'locale', 'format', 'minView', 'maxView', 'startView', 'position', 'inline', 'validate', 'autoclose', 'setOnSelect', 'today',
'keyboard', 'showHeader', 'leftArrow', 'rightArrow', 'additions'
], function (attr) {
if (!angular.isDefined($scope[attr]))
Expand Down Expand Up @@ -397,11 +399,17 @@
},
change: function (view) {
var nextView = $scope.views.all.indexOf(view), minView = $scope.views.all.indexOf($scope.minView), maxView = $scope.views.all.indexOf($scope.maxView);
if (nextView < 0 || nextView > maxView) {
var update = function () {
utility_1.setValue($scope.view.moment, $scope, $ctrl, $attrs);
$scope.view.update();
if ($attrs['ngModel'])
$ctrl.$commitViewValue();
};
if ($scope.setOnSelect)
update();
if (nextView < 0 || nextView > maxView) {
if (!$scope.setOnSelect)
update();
if ($scope.autoclose)
_this.$timeout($scope.view.close);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-moment-picker.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/angular-moment-picker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-moment-picker",
"version": "0.9.9",
"version": "0.9.10",
"description": "Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js",
"main": "dist/angular-moment-picker.js",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/definitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IDirectiveScope extends ng.IScope {
inline?: boolean;
validate?: boolean;
autoclose?: boolean;
setOnSelect?: boolean;
isOpen?: boolean;
today?: boolean;
keyboard?: boolean;
Expand Down
56 changes: 31 additions & 25 deletions src/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ export default class Directive implements ng.IDirective {
public transclude = true;
public template = templateHtml;
public scope = {
value: '=?momentPicker',
model: '=?ngModel',
locale: '@?',
format: '@?',
minView: '@?',
maxView: '@?',
startView: '@?',
minDate: '=?',
maxDate: '=?',
startDate: '=?',
disabled: '=?disable',
position: '@?',
inline: '@?',
validate: '=?',
autoclose: '=?',
isOpen: '=?',
today: '=?',
keyboard: '=?',
showHeader: '=?',
additions: '=?',
change: '&?',
selectable: '&?'
value: '=?momentPicker',
model: '=?ngModel',
locale: '@?',
format: '@?',
minView: '@?',
maxView: '@?',
startView: '@?',
minDate: '=?',
maxDate: '=?',
startDate: '=?',
disabled: '=?disable',
position: '@?',
inline: '@?',
validate: '=?',
autoclose: '=?',
setOnSelect: '=?',
isOpen: '=?',
today: '=?',
keyboard: '=?',
showHeader: '=?',
additions: '=?',
change: '&?',
selectable: '&?'
};

constructor(
Expand All @@ -51,7 +52,7 @@ export default class Directive implements ng.IDirective {
$transclude(($transElement: ng.IAugmentedJQuery) => {
// one-way binding attributes
angular.forEach([
'locale', 'format', 'minView', 'maxView', 'startView', 'position', 'inline', 'validate', 'autoclose', 'today',
'locale', 'format', 'minView', 'maxView', 'startView', 'position', 'inline', 'validate', 'autoclose', 'setOnSelect', 'today',
'keyboard', 'showHeader', 'leftArrow', 'rightArrow', 'additions'
], (attr: string) => {
if (!angular.isDefined($scope[attr])) $scope[attr] = this.provider[attr];
Expand Down Expand Up @@ -261,11 +262,16 @@ export default class Directive implements ng.IDirective {
let nextView = $scope.views.all.indexOf(view),
minView = $scope.views.all.indexOf($scope.minView),
maxView = $scope.views.all.indexOf($scope.maxView);

if (nextView < 0 || nextView > maxView) {
const update = () => {
setValue($scope.view.moment, $scope, $ctrl, $attrs);
$scope.view.update();
if ($attrs['ngModel']) $ctrl.$commitViewValue();
};

if ($scope.setOnSelect) update();
if (nextView < 0 || nextView > maxView) {
if (!$scope.setOnSelect) update();
if ($scope.autoclose) this.$timeout($scope.view.close);
} else if (nextView >= minView) $scope.view.selected = view;
}
Expand Down
2 changes: 2 additions & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IProviderOptions {
inline?: boolean;
validate?: boolean;
autoclose?: boolean;
setOnSelect?: boolean;
today?: boolean;
keyboard?: boolean;
showHeader?: boolean;
Expand Down Expand Up @@ -54,6 +55,7 @@ export default class Provider implements angular.IServiceProvider {
inline: false,
validate: true,
autoclose: true,
setOnSelect: false,
today: false,
keyboard: false,
showHeader: true,
Expand Down

0 comments on commit e665cd6

Please sign in to comment.