Code Monkey home page Code Monkey logo

angular-material-datetimepicker's Introduction

Angular Material DateTimePicker

Originally designed for Bootstrap Material, this has been modified to work with Angular Material. This is an Android style date-time picker for Angular Material. Some added features include:

  • Double click to select date or time
  • Swipe left to go to next month or Swipe right to go to previous month.

Updates

** I have kept this section of the document as an acknowledgement for all the work done on the original Bootstrap Material plugin **

Date Author Description
2017-01-30 hexadecy Add support only for angular 1.5.x - 1.6.x ($onInit)
2015-11-12 logbon72 Adapted plugin for Angular Material
2015-10-19 benletchford Fixed not being able to tab into input
2015-10-19 drblue Fixed erroneous package.json-file
2015-10-19 Perdona Fix auto resize when month has 6 weeks
2015-07-01 T00rk Redesigned element without using modal
2015-06-16 T00rk Use Timepicker alone / Display short time (12 hours)
2015-06-13 T00rk Fixed issue with HTML value tag
2015-05-25 T00rk Changed repo name to bootstrap-material-datetimepicker *
2015-05-12 T00rk Added parameters for button text
2015-05-05 Sovanna FIX undefined _minDate in isBeforeMaxDate func
2015-04-10 T00rk Little change in clock design
2015-04-10 Peterzen Added bower and requirejs support
2015-04-08 T00rk Fixed problem on locale switch
2015-03-04 T00rk Added Time picker

Dependencies

Depends on the following library:

  • AngularJS Material
  • AngularJS Animate
  • AngularJS Aria
  • AngularJS
  • Moment

Installing via yarn or npm

yarn add ng-material-datetimepicker
npm i ng-material-datetimepicker

Live Example

Click here to see live examples.

Usage

Add the plugin module as a dependency to your AngularJS module:

    angular.module('myAwesomeModule', [
      //other dependencies ignored
      'ngMaterialDatePicker'
    ]);

This plugin exposes a directive which should be used as an attribute for an input element. The directive is mdc-datetime-picker. An example of this is given below:

    <md-input-container flex-gt-md="30">
        <label>Timepicker Only</label>
        <input mdc-datetime-picker date="false" time="true" type="text" id="time" short-time="true"
               show-todays-date
               placeholder="Time"
               min-date="minDate"
               format="hh:mm a"
               ng-change="vm.saveChange()"
               ng-model="time">
    </md-input-container>

Directive Attributes

The directive accepts several attributes which are described below:

Name Type Description
ng-model (String|Date|Moment) Initial Date or model to assign the date to
ng-change Function A function to call when the input value changes.
format String MomentJS Format,defaults to HH:mm for time picker only, YYYY-MM-DD for date picker only and YYYY-MM-DD HH:mm for both timepicker and date picker
short-time Boolean true => Display 12 hours AM|PM
min-date (String|Date|Moment) Minimum selectable date
max-date (String|Date|Moment) Maximum selectable date
date Boolean true => Has Datepicker (default: true)
time Boolean true => Has Timepicker (default: true)
cancel-text String Text for the cancel button (default: Cancel)
today-text String Text for the today button (default: Today)
ok-text String Text for the OK button (default: OK)
week-start Number First day of the week (default: 0 => Sunday)

Date/Time Dialog Service

You can also use the Date Time picker as a service, using the mdcDateTimeDialog service. The dialog returns a promise which is resolved with the selected date-time value and rejected on cancellation.

Example usage:

    someModule.controller('DemoCtrl', function ($scope, mdcDateTimeDialog) {

      $scope.displayDialog = function () {
        mdcDateTimeDialog.show({
          maxDate: $scope.maxDate,
          time: false
        })
          .then(function (date) {
            $scope.selectedDateTime = date;
            console.log('New Date / Time selected:', date);
          }, function() {
            console.log('Selection canceled');
          });
      };
    })

The mdcDateTimeDialog.show accepts the same options as the directive.

     {
       date: {boolean} =true,
         time: {boolean} =true,
         format: {string} ='YYYY-MM-DD',
         minDate: {strign} =null,
         maxDate: {string} =null,
         currentDate: {string} =null,
         lang: {string} =mdcDatetimePickerDefaultLocale.locale,
         weekStart: {int} =0,
         shortTime: {boolean} =false,
         cancelText: {string} ='Cancel',
         todayText: {string} ='Today',
         okText: {string} ='OK',
         amText: {string} ='AM',
         pmText: {string} ='PM'
     }

Important Note on Using Locales

Please see this issue. To use a locale with your date time picker dialog, you'll have to include the moment.js locale file.

angular-material-datetimepicker's People

Contributors

2ernestkg avatar aroddy avatar contmp avatar darit avatar dhaval85 avatar drblue avatar hexadecy avatar indream avatar j-walker23 avatar jpike88 avatar logbon72 avatar lohithanand avatar nikoskalogridis avatar perdona avatar sovanna avatar t00rk avatar tezqa avatar therajumandapati avatar thewisenerd avatar vidanger 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

angular-material-datetimepicker's Issues

Closes already open popups when coming to for front of the screen

The datetime picker is being called from another modal popup and is forcing the original popup to close stopping me from returning to the original popup to continue what i was doing. Would it be possible to add a skipHide:true to the date time picker popup modal or some other method to stop the pop up from prematurely closing the parent modal popup?

Error: [$compile:multidir] Multiple directives

Hi,

Thanks for this great lib!
This is my first time to use this lib and I'm encountering an error.
Here's the error on my browser's console: Error: [$compile:multidir] Multiple directives [input (module: app), mdcDatetimePicker] asking for new/isolated scope on: <input mdc-datetime-picker date="true" time="true" type="text" id="datetime" placeholder="Date" min-date="date" ng-model="dateTime" />

Hope you can help me with this.

Thanks.

Is this working in md-dialog box?

Is this working in md-dialog box?
I want to used angular-material-datetimepicker in mg-dialog box.
But, mg-dialog box close when angular-material-datetimepicker time/date picker open.

there is any way to use angular-material-datetimepicker in mg-dialog box?

Usability - Easy year selection

For things like date of birth, there needs to be an easier way to choose the year.

I have been trying to place an up/down arrow next to the year, and having it increment or decrement the date by one year when pressed.

The problem is that I'm trying to have that talk to the calendar display to trigger an update so it can re-center over the new date. Any suggestions?

Modifications made:

Modified the template variable:
+ ' <div class="dtp-actual-year">{{picker.currentDate.format("YYYY")}}</div>'
// new lines added below
+ ' <div ng-click="picker.incrementYear(1)">year up</div>'
+ ' <div ng-click="picker.incrementYear(-1)"class="dtp-actual-year">year down</div>'

Function added after the isPM function:

incrementYear: function (amount) {
this.selectDate(this.currentDate.add('year', amount));
}

Problem using "DD/MM/YYYY" format

When specifying "DD/MM/YYYY" as format, the datetimepickers date becomes invalid and shows an empty input.
The value I use as date = "2016-05-23T11:20:21.7329621+02:00"

My findings:
Setting the format at line 115: scope.currentDate = moment(scope.currentDate, scope.format); in angular-material-datetimepicker.js, the m.isValid() at line 125 returns false.

How to config the background color

Hi logbon72, This module is very good, I like it. However I want to change the default background color to match my app theme. Can you show me how to do that? Thank you.

Outdated bower repository

$mdDialog option 'skipHide: true' is not setted in the Dialog config object. This option allows the datetime picker dialog open above another dialog.

Another interesting config is 'clickOutsideToClose: true', this option allows the dialog is closed when clicked outside or when escape key is pressed.

Inputs are not bluring after selection is made

The md-input-focused class is not being removed from the input-container after the selection is made, which is causing visual inconsistencies on the page after a change has been made to a date field.

There is a conflict with Angular Material v1.1.1

Hello,

I'm trying to install it via Bower and I have an issue

ECONFLICT Unable to find suitable version for angular-material

I'm using Angular Material v1.1.1.

Could you please provide instructions how to resolve it?

Thanks,
Alexander

DateTime popup not displaying properly (CSS Not loading)

I have tried to integrate your library into my app, but unfortunately the css is not loading properly. When the popup load the css is not being applied to it. I even made sure that the CSS for the popup was loading before bootstrap.
Should I also include other files such as: beautifier.js, and highlights and their appropriate CSS files? Because I did but still not getting what I expected.
mddatetimepopup

Clear Date

Hi,

How can I clear the date from the input field?

Thanks,
Hemant.

npm package, ownership transfer

Hello,

I don't use bower and I needed to use this package under npm. There was no npm package, but I can see package.json file, so I created it here. I will happily transfer the ownership if you tell me your logins.

Thanks for the plugin!

When using in modal window has a delay

It seems kind off heavy to load when using on a modal dialog, takes like 2, 3 seconds to display the clock.

As note, I'm using it with another services and angular templating in the page, that might be slowing it down.

Usage of old version of moment.js

Hi Logbon,

This is a very nice and interactive module. But currently the one of it's dependency (Moment.js) is too old to be utilized. As moment.js updated some of their APIs.

Please update the package with suitable version.

Possibility of returning string to model

Not an issue but a suggestion

The date picker returns a date object or a moment object to the model and that makes it difficult to submit through a form as compared to when it is a string.

e.g. if the ng-model="response". $scope.response in the controller should be a string (not an object).

The moment or date object is technically not needed. You can use parseDate and formatDate to convert string to date and date to string when the datepicker is opened and a date is selected respectively.

Type date instead of open a modal

Is there a way to choose type a date instead of automatically open a modal when the input get focused??? Like have a button side-by-side in a input, and the modal opens when the users click that button, but if the user prefer, he can type manually a date/time (like using a directive to mask or something like that)?

Modal inside another modal

Greetings,

Is it possible to add this parameter "skipHide: true" in the $mdDialog.show call?

          $mdDialog.show({
              template: template,
              controller: PluginController,
              controllerAs: 'picker',
              locals: locals,
              openFrom: element,
              parent: angular.element(document.body),
              bindToController: true,
              disableParentScroll: false,
              skipHide: true
            })

This gonna make possible to show the DatePicker modal inside of another modal.

Regards,

Fabio

moment is not defined

I followed the steps here: https://www.npmjs.com/package/bower-webpack-plugin
And I run
bower install angular-material-datetimepicker
Add
require("momentjs");
require("angular-material-datetimepicker");
in entry.js
run
webpack -d --watch
everything is fine. But when I open index.html in the browser, it said
Uncaught ReferenceError: moment is not defined
I try the bootstrap demo in the example. It's works fine. I don't know if I forgot anything else or if there is a bug in angular-material-datetimepicker?
Thanks for help!

How to programmatically trigger the click

Great directive, Thanks for sharing it

how you will hack the directive to allow keyboard support, lets say if i press Alt-H , want to popup this awesome date time picker.

angular.element(elmName).triggerHandler('click');
angular.element(elmName).trigger('click');

none of them work

Datetime picker modal picks time in UTC

In the input box the date time is shown as 2016-06-12 14:10:00 but when I click on the input box to open the datetime picker modal, the time is shown in UTC (in my case UTC-5:30).
So it shows 08:40. How to fix this?

Suggestion: Use without a popup!

This would be fantastic if we could use it without the popup feature. For example, the Bootstrap UI datepicker will simply display the calendar as-is.

Has anyone suggested this or is there a PR in progress? Nice module

Month scrolling not working on touch screen

I had this working previously on my ionic application. I confirmed this is only on mobile by running ionic serve to run the application in my Mac's Chrome browser. See screenshots below.

Desktop
screen shot 2016-10-12 at 6 50 17 pm

Mobile Android device
screenshot_2016-10-12-18-50-37

Cannot load module via npm

I would like to load this module via npm.
If I run npm i There is some progress showing up, but I cannot find the package in my node_modules directory.
There are no errors flashing up.

I added this to my package.json file:

{
  "dependencies": {
    "angular-material-datetimepicker": "git://github.com/logbon72/angular-material-datetimepicker#v1.3.1"
  }
}

I'm not sure what is causing this.
Might it be the ignored pattern "/.*" in the package.json?

How to set the minDate as a string?

I'm trying to set the minDate as a string in the HTML. I've tried:
min-date="2016-08-10"
But this doesn't work. Should it be a different format?

In using min-date and max-date attribute, while selecting date from other months from default selected date month, the calendar scrolls down to the bottom

If i used min-date and max-date attribute,

while selecting date from other months from default selected date month, the calendar scrolls down to the bottom.

This is because of wrong value of md-top-index in mdcDatetimePickerCalendar directive.

In the line 563 of our js file, we update calendar.topIndex from currentMonthIndex method alone.

var index = currentMonthIndex(nDate);
if (calendar.topIndex != index) {
calendar.topIndex = index;
}

Here we have to subtract calendar.months[0] from currentMonthIndex method to get exact index to set calendar.topIndex so that md-top-index.

So the correct code will be

var index = currentMonthIndex(nDate);
if (calendar.topIndex != index) {
calendar.topIndex = index - calendar.months[0];
}

Kindly fix this issue as soon as possible.
Thanks

Clock looks horrible! Everything is messed up!

I'm trying to use the date picker, I took the code from the examples and added it to my page:

<md-input-container class="col-md-2 col-md-offset-5" flex-gt-sm>
      <label>Time</label>
      <input mdc-datetime-picker="" date="false" time="true" type="text" id="time" short-time="true"
            placeholder="Time" min-date="minDate" format="hh:mm a" ng-model="time" class="md-input">
</md-input-container>

But the clock looks really bad and also the buttons are on the top!

capture2

Any idea about what could be the problem?

Support of Timestamp

Hello Guys,

Really good job.

However I want to know is there any way that the output is being set as Timestamp (long) and not as a Date object?

Thanks,
Dhaval

Not compatible with Angular 1.6.x

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.