Git Product home page Git Product logo

bootstrap-ui-datetime-picker's Introduction

Bootstrap-UI/datetime-picker

This project is not actively maintained at the moment, as i work with Angular now and not AngularJs. If you have a bug please submit a PR and i will go over the change and pull it in.

AngularJs directive to use a date and/or time picker as a dropdown from an input.

Demo

Installation

To use the directive you must have the following angular-ui bootstrap directives included already

  • DatePicker
  • TimePicker

You should already have the ui.bootstrap dependancy included in your app.js file like below, You then need to add ui.bootstrap.datetimepicker, as so

angular.module('app', ['ui.bootstrap', 'ui.bootstrap.datetimepicker']);

Download the source from dist/datetime-picker.min.js file and include it in your project.

Or use Bower (thank you krico for setup)

bower install --save bootstrap-ui-datetime-picker

and link with bower_components/bootstrap-ui-datetime-picker/dist/datetime-picker.min.js

Usage

You have the following properties available to use with the directive. All are optional unless stated otherwise

  • ngModel (required) - Your date object
  • isOpen - (true/false)
  • closeOnDateSelection (true/false)
  • closeOnTimeNow (true/false)
  • enableDate (true/false)
  • enableTime (true/false)
  • buttonBar (object)
  • initialPicker ('date'/'time')
  • reOpenDefault (false/'date'/'time') - NOTE: true not supported
  • datepickerOptions (object)
  • timepickerOptions (object)
  • defaultTime (string)
  • saveAs (boolean|function|'ISO'|'json'|'number')
  • readAs (boolean|function)
isOpen

Whether the popup/dropdown is visible or not. Defaults to false

closeOnDateSelection

Close popup once a date has been chosen. TimePicker will stay open until user closes.

closeOnTimeNow

Close popup once a time has been chosen via now button.

enableDate

Whether you would like the user to be able to select a date. Defaults to true

enableTime

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.

datepickerOptions

Object to configure settings for the datepicker (can be found on angularUI site)

timepickerOptions

Object to configure settings for the timepicker (can be found on angularUI site)

defaultTime

Initial time when a new date is selected (e.g. "14:00:00" or "2:00 pm")

whenClosed

An callback function to call when the picker dropdown is closed. See demo for more details.

saveAs

A boolean value to switch saving the Date to the model as a string, or a ngModel.$parsers function to take over the transformation from the Date object to a string. Possible values:

  • true
  • false
  • 'ISO' (Date.toISOString())
  • 'json' (Date.toJSON())
  • 'number' (Date.valueOf())
  • a function accepting a value parameter and returning the converted value to save to the model. Note: If using an html5 input type, the default parser will use Date.toLocaleString() to convert to a string. To override this, provide a function with your desired formatted conversion. Otherwise all other input types will use the supplied date format.
readAs

A boolean value to convert a string (or Date.valueOf()) value back to a Date object from the ngModel, or a ngModel.$formatters function to take over the transformation completely.

uiDatetimePickerConfig

Now datetimePicker options are globally set by default. If you do not state the values within the declaration, the config options are used instead. Here are the default options

.constant('uiDatetimePickerConfig', {
    dateFormat: 'yyyy-MM-dd HH:mm',
    defaultTime: '00:00:00',
    html5Types: {
        date: 'yyyy-MM-dd',
        'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss',
        'month': 'yyyy-MM'
    },
    initialPicker: 'date',
    reOpenDefault: false,
    enableDate: true,
    enableTime: true,
    buttonBar: {
        show: true,
        now: {
            show: true,
            text: 'Now',
            cls: 'btn-sm btn-default'
        },
        today: {
            show: true,
            text: 'Today',
            cls: 'btn-sm btn-default'
        },
        clear: {
            show: true,
            text: 'Clear',
            cls: 'btn-sm btn-default'
        },
        date: {
            show: true,
            text: 'Date',
            cls: 'btn-sm btn-default'
        },
        time: {
            show: true,
            text: 'Time',
            cls: 'btn-sm btn-default'
        },
        close: {
            show: true,
            text: 'Close',
            cls: 'btn-sm btn-default'
        },
        cancel: {
            show: false,
            text: 'Cancel',
            cls: 'btn-sm btn-default'
        }
    },
    closeOnDateSelection: true,
    closeOnTimeNow: true,
    appendToBody: false,
    altInputFormats: [],
    ngModelOptions: {},
    saveAs: false,
    readAs: false
})

Css

Personally i dont like the look of the angular-ui calendar itself, this is because the buttons are configured to use the btn-default style. To get round this there are 3 css classes applied to the datetimepicker and depending on the picker that is being shown. These classes surround the div element that contains the angular-ui datepicker and timepicker. Using these classes you can change the style of the calendar. The class are

.datetime-picker-dropdown

Applied to the dropdown that the pickers are contained within

.datetime-picker-dropdown > li.date-picker-menu

Applied when the date picker is visible

.datetime-picker-dropdown > li.time-picker-menu

Applied when the time picker is visible. The buttons in the buttonBars can be overridden by setting the css classes as stated above

EXAMPLE

For example, if i add this css code, you will see the difference to the calendar in the images below

.datetime-picker-dropdown > li.date-picker-menu div > table .btn-default {
    border: 0;
}
BEFORE

alt tag

AFTER

alt tag

Example

Here is an example to use the directive with a bootstrap input, displaying a calendar button

HTML

<p class="input-group">
    <input type="text" class="form-control" datetime-picker="dd MMM yyyy HH:mm" ng-model="myDate" is-open="isOpen"  />
    <span class="input-group-btn">
        <button type="button" class="btn btn-default" ng-click="openCalendar($event, prop)"><i class="fa fa-calendar"></i></button>
    </span>
</p>

JAVASCRIPT

app.controller('MyController', function() {
    var that = this;

    this.isOpen = false;

    this.openCalendar = function(e) {
        e.preventDefault();
        e.stopPropagation();

        that.isOpen = true;
    };
});

Bug

If you do find a bug, can you please create a plunkr to replicate the error before raising an issue. Attach the plunkr as a link to the issue so i can replicate the error and work out a solution.

Pull Requests

If you submit a PR, please test your changes against the demo page to make sure no functionality has been broken.

Support

This was developed using angular-ui bootstrap Version: 1.2.0 - 2016-04-07. If you have a bug, please check what version of angular-ui you are using. If you are using a version prior to this, then please upgrade if you can and try it. If the problem persists, please let me know. I do have a day job but will try to get back to you asap. If you can fix the bug, then let me know how, or even better, submit a pull request.

bootstrap-ui-datetime-picker's People

Contributors

adamdoyle avatar afro1114 avatar alexfess avatar blok1993 avatar brahimelkecha16 avatar bryant1410 avatar carlescs-duplicate avatar chriscalitz avatar deostroll avatar doublesharp avatar erikdubbelboer avatar fluky avatar gillardo avatar hexencoded avatar johnzeringue avatar josephgarrone avatar krico avatar kyse avatar maria201181 avatar mightydes avatar mixxr avatar n0namedguy avatar niek avatar parabolt avatar szkrd avatar tienslebienz avatar toncid avatar travist avatar v-rr avatar vidyapati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootstrap-ui-datetime-picker's Issues

Npm publish

Please publish the package to npm, right now we're using the direct github url which is far from ideal. Thanks!

Time Window remains Open

If I have two timepickers, and I click both timepicker icons, both remains open. I do not have any option to close the other one if I click outside.

Need Callback on Close

I have two datetime pickers on the same page for the start and end time of an event. What I want to do is to set the end time automatically to, say 3 hours, after the start time when the start time datetime picker is closed.

The approach I have in mind now is to add a callback upon closing the datetime picker. Is it the right approach? If so, please add a callback for closing the picker. Otherwise please suggest alternatives. Thanks.

Too many watchers

Hello,

when i load datetime-picker, i got 700 watchers !!!!
Please use angularjs bind once or thank you optimize it in another way !

angularjs known performance losses from 1000 watchers ...

displaying meridians

Great directive, thank you so much.

I'm just using the datetime format from the demo sample in the html code:
datetime-picker="MM/dd/yyyy HH:mm"

Is there any way to display meridians in the above formatter?

I also tried adding a timepicker-options attribute and specifying the showMeridian property in the controller:
$scope.timeOpts = {showMeridian: true}

Meridians still aren't displaying (AM, PM). Any suggestions? Thanks in advance.

update model only after pressing done

is there any way to make the model update only after the user press the done button?

In addition the model should revert to orig value (if there was any) if the popup is closed(canceled) in any other way.

DateTime Picker in ui.modal

Im having issues using the datetime picker in a modal window ...
After opening the modal on formfield click the picker opens as usual.
Once closed a click on the formfield does not open the picker again ...
Pressing key down with the keyboard cursors opens the picker.

Do you have any hint whats the issue here ?

regards

How to set default time on date selection

I disabled timepicker, but i would like to set some default time when i select date.
I tried with timepicker-options="{defaultTime:'01:00:00'}" but it's not working

No versions found in git://github.com/gillardo/bootstrap-ui-datetime-picker.git

When I try to put a version number in my bower.json:

    "bootstrap-ui-datetime-picker": "~1.0.7",

I got the following error doing bower update bootstrap-ui-datetime-picker

bower bootstrap-ui-datetime-picker#~1.0.7       not-cached git://github.com/gillardo/bootstrap-ui-datetime-picker.git#~1.0.7
bower bootstrap-ui-datetime-picker#~1.0.7          resolve git://github.com/gillardo/bootstrap-ui-datetime-picker.git#~1.0.7
bower bootstrap-ui-datetime-picker#~1.0.7     ENORESTARGET No tag found that was able to satisfy ~1.0.7

Additional error details:
No versions found in git://github.com/gillardo/bootstrap-ui-datetime-picker.git

Could you please address that? Thanks @Gillardo.

Globally configured texts are never used

The following chunk makes sure that the scope value is always set:

// default text
scope.todayText = scope.todayText || 'Today';
scope.nowText = scope.nowText || 'Now';
scope.clearText = scope.clearText || 'Clear';
scope.closeText = scope.closeText || 'Close';
scope.dateText = scope.dateText || 'Date';
scope.timeText = scope.timeText || 'Time';

Afterwards, the getText() function never fall back to the global config, i.e. scope[key + 'Text'] is always set:

scope.getText = function (key) {
    return scope[key + 'Text'] || uiDatetimePickerConfig[key + 'Text'];
};

Thoughts?

Cannot read property 'getHours' of null

Hi,

when you select date and time and you press clear button in time selection, nothing happens and this error appears:

TypeError: Cannot read property 'getHours' of null
at Scope.link.d.dateSelection (http://localhost:3000/scripts/libs/bootstrap-ui-datetime-picker/datetime-picker.min.js:4:2999)
at Scope.link.d.select (http://localhost:3000/scripts/libs/bootstrap-ui-datetime-picker/datetime-picker.min.js:4:4371)
at $parseFunctionCall (http://localhost:3000/scripts/libs/angular/angular.js:12332:18)
at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:3000/scripts/libs/angular/angular.js:22949:17)
at Scope.$get.Scope.$eval (http://localhost:3000/scripts/libs/angular/angular.js:14383:28)
at Scope.$get.Scope.$apply (http://localhost:3000/scripts/libs/angular/angular.js:14482:23)
at HTMLButtonElement. (http://localhost:3000/scripts/libs/angular/angular.js:22954:23)
at HTMLButtonElement.jQuery.event.dispatch (http://localhost:3000/scripts/libs/jquery/jquery.js:4409:9)
at HTMLButtonElement.jQuery.event.add.elemData.handle (http://localhost:3000/scripts/libs/jquery/jquery.js:4095:28)

feature request: watch min/max date

The raw angular-ui datepicker has a watch on a few attrs, in particular for what I'm interested in on min-date and max-date. In this package these don't seem to have a watch; could this be added and passed through to the angular-ui watch?

Add a top-level class

Widget's HTML is wrapped into a <ul class="dropdown-menu dropdown-menu-left" ...> element.

It would be nice to have a custom class here (e.g. datetime-picker-dropdown). This way it will be possible to force pop-up's min-width through CSS, because buttons wrap when in the timepicker view (when button labels are longer than expected).

ng-model is updated well with datetime-picker="mediumDate" but not with datetime-picker="yyyy/MM/dd HH:mm"

Hello.

I implemented the directive on my app with this:

<input type="text"
                   placeholder="Fecha de publicación"
                   class="form-control"
                   datetime-picker="yyyy/MM/dd HH:mm"
                   is-open="open.date1"
                   datepicker-options="dateOptions"
                   enable-time="true"
                   ng-model="dates.date1"
                   show-button-bar="true"/>
            <span class="input-group-btn">
                <button type="button" class="btn btn-default" ng-click="openCalendar($event, 'date1')"><i class="fa fa-calendar"></i></button>
            </span>

And in the controller:

//Datepickers
        $scope.dates = {
            date1: new Date()
        };

        $scope.open = {
            date1: false
        };

        $scope.dateOptions = {
            showWeeks: false,
            startingDay: 1
        };

        $scope.openCalendar = function(e, date) {
            $scope.open[date] = true;
        };

When I submit the form I console.log(dates.date1) of datepicker it returns me undefined if the datetime-picker="yyyy/MM/dd HH:mm" but if is datetime-picker="mediumDate" return the ng-model well. Any suggestions please?

Doesn't seem to work in Chrome

I can't get this to work in Chrome, not even the listed plunker demo. Nothing happens when clicking the button that is supposed to open the date/time picker. The demo DOES work in IE and Firefox, so presumably some sort of workaround is needed in Chrome? The regular bootstrap datepicker works in Chrome as far as I've tested. I'm using Chrome Version 40.0.2214.111 m in Windows 8.1.

Bootstrap 4 compatibility

Right now Bootstrap 4 is still in alpha but it's worth noting some of the changes that will affect this project.

2 of the changes I've run into so far:

  • Glyphicons are no longer included with Bootstrap (documented)
  • .btn-default has been dropped, replaced with .btn-secondary (?, undocumented)

Example of how the datetimepicker looks with Bootstrap 4 Alpha (affected by both items listed):

Missing License

Could you please consider adding a MIT license to this project?

Cannot set min & max for time

'max-date' & 'min-date' are working for the date picker, but for the time picker, the 'min' & 'max' attrs on the DOM are not working. For example,

<input type="text" class="form-control" datetime-picker="MM/dd/yyyy HH:mm" 
               ng-model="ctrl.dates.date3" is-open="ctrl.open.date3" maxTime="today"/>

issue readonlyInput

Hi,

I have a problem with feature readonlyInput in

$scope.timeOptions = {
readonlyInput: true,
showMeridian: false
};

I dont have edit timepicker, I have change readonlyInput to false

Problem with validation

Hello,
I have a problem with this control when validating. When the bound date is null, the first time I submit my form I get the control styled as if it was wrong. See this plunkr: http://plnkr.co/nx65o9

If I change the two undefined in the parseDate function to null it seems to work ok, but I don't know if this would cause other problem down the way.

Can I change timezone?

<input type="text" class="form-control" 
datetime-picker="yyyy년 MM월 dd일 HH시 mm분" 
datepicker-options="datePickerOptions" 
timepicker-options="timePickerOptions" 
ng-model="episode.air_date" 
is-open="isOpenedDatePicker" 
ng-change="checkAirDate()" />

It's works well in input form date and time as 'KST'.
But when I print them {{ model_name }} in markup, the time values setted as 'UTC'.

The Plunker demo has same problem.
Do I have to change timezone?

add "showWeek" setting

as in ui-bootstrap datepicker :

show-weeks (Defaults: true) : Whether to display week numbers.

Can't change date format.

I am using ui-bootstrap 0.13.0 (I also tried with 0.13.3) but I could not alter the date format for uiDatetimePickerConfig . I resorted to directly modifying the datepicker-picker code to change the default.. and it still does not alter the format in the picker.

The datepickerOptions and timepickerOptions doesn't work

When using the options attr nothing happend.

I change this lines and it worked, the last .children[0] should be removed:

var r = angular.element(q.children()[0].children[0].children[0]);

var s = angular.element(q.children()[1].children[0].children[0]);

to:

var r = angular.element(q.children()[0].children[0]);

var s = angular.element(q.children()[1].children[0]);

thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.