diff --git a/README.md b/README.md index 18a73b4..867a7f7 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ You have the following properties available to use with the directive. All are * enableDate (true/false) * enableTime (true/false) * buttonBar (object) +* initialPicker ('date'/'time') +* reOpenDefault (false/'date'/'time') - NOTE: `true` not supported * dateDisabled * datepickerOptions (object) * timepickerOptions (object) @@ -45,6 +47,10 @@ Whether you would like the user to be able to select a time. Defaults to true ##### buttonBar To show or hide the button bar, or any of the buttons inside it. Defaults to the uiDatetimePickerConfig. Only specify the elements that you want to override, as each button defaults to the uiDatetimePickerConfig setup, if it is not configured on scope of the datetimePicker +##### initialPicker +The initial picker to open when the control is first pressed +##### reOpenDefault +The picker to set as the picker to open once the control has already been opened at least once. Setting to `false` will default to the date picker if both date and time are enabled, or just the enabled control if only time or date is in use. ##### dateDisabled From angularUI site -> An optional expression to disable visible options based on passing date and current mode (day|month|year). ##### datepickerOptions @@ -70,6 +76,8 @@ Now datetimePicker options are globally set by default. If you do not state the 'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss', 'month': 'yyyy-MM' }, + initialPicker: 'date', + reOpenDefault: false, enableDate: true, enableTime: true, buttonBar: { diff --git a/datetime-picker.js b/datetime-picker.js index fbd1688..40c2493 100644 --- a/datetime-picker.js +++ b/datetime-picker.js @@ -1,4 +1,4 @@ -angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position']) +angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position']) .constant('uiDatetimePickerConfig', { dateFormat: 'yyyy-MM-dd HH:mm', defaultTime: '00:00:00', @@ -7,6 +7,8 @@ 'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss', 'month': 'yyyy-MM' }, + initialPicker: 'date', + reOpenDefault: false, enableDate: true, enableTime: true, buttonBar: { @@ -60,8 +62,19 @@ scope.enableDate = angular.isDefined(scope.enableDate) ? scope.enableDate : uiDatetimePickerConfig.enableDate; scope.enableTime = angular.isDefined(scope.enableTime) ? scope.enableTime : uiDatetimePickerConfig.enableTime; + // determine default picker + scope.initialPicker = angular.isDefined(attrs.initialPicker) ? attrs.initialPicker : (scope.enableDate ? uiDatetimePickerConfig.initialPicker : 'time'); + + // determine the picker to open when control is re-opened + scope.reOpenDefault = angular.isDefined(attrs.reOpenDefault) ? attrs.reOpenDefault : uiDatetimePickerConfig.reOpenDefault; + + // check if an illegal combination of options exists + if (scope.initialPicker == 'date' && !scope.enableDate) { + throw new Error("datetimePicker can't have initialPicker set to date and have enableDate set to false."); + } + // default picker view - scope.showPicker = scope.enableDate ? 'date' : 'time'; + scope.showPicker = !scope.enableDate ? 'time' : scope.initialPicker; var isHtml5DateInput = false; @@ -394,7 +407,7 @@ // if enableDate and enableTime are true, reopen the picker in date mode first if (scope.enableDate && scope.enableTime) - scope.showPicker = 'date'; + scope.showPicker = scope.reOpenDefault === false ? 'date' : scope.reOpenDefault; // if a on-close-fn has been defined, lets call it // we only call this if closePressed is defined! @@ -531,6 +544,8 @@ isOpen: '=?', enableDate: '=?', enableTime: '=?', + initialPicker: '=?', + reOpenDefault: '=?', dateDisabled: '&', customClass: '&', whenClosed: '&' diff --git a/example/index.html b/example/index.html index f70b516..5f548ad 100644 --- a/example/index.html +++ b/example/index.html @@ -7,7 +7,7 @@ - +