Coder Social home page Coder Social logo

ion-datetime-picker's Introduction

ion-datetime-picker

GitHub version Bower version npm version Ionic version License
GitHub issues GitHub issue stats GitHub pull requests Github pull request stats GitHub contributors

Date and/or time picker for awesome Ionic framework v1

Introduction

I made this component because of poor implementation of native datetime picker in Android webview. How funny it was when I discovered that I can only pick a time between 0:00 and 11:59 on my 24-hour clock phone :)

Looking for a picker that works with Ionic framework v2?

Features

The ion-datetime-picker component has these features:

  • Make Date picker, Time picker, Datetime picker
  • Choose Sunday or Monday as the first day of the week
  • Use 12-hour or 24-hour clock
  • Pick time with or without seconds
  • Configure popup title and button labels and classes
  • Configure i18n to get weekdays and months in your language
  • Configure size of a step

Demo

Demo app is available - enter code 8d75a0ec into Ionic View. Live demo is available on Codepen.

#Screenshots

Date picker

Time picker

Datetime picker

Installation

  1. Use bower or npm to install the new module:

    bower install ion-datetime-picker --save
    npm install ion-datetime-picker --save
  2. Import the ion-datetime-picker javascript and css file into your HTML file (or use wiredep):

    <script src="lib/ion-datetime-picker/release/ion-datetime-picker.min.js"></script>
    <link href="lib/ion-datetime-picker/release/ion-datetime-picker.min.css" rel="stylesheet">
  3. Add ion-datetime-picker as a dependency on your Ionic app:

    angular.module("myApp", ["ionic", "ion-datetime-picker"]);

Usage

Put the ion-datetime-picker directive alongside the ng-model wherever you want to tap to show the picker:

<ion-list>
  <div class="item" ion-datetime-picker ng-model="datetimeValue">
    {{datetimeValue| date: "yyyy-MM-dd H:mm:ss"}}
  </div>
</ion-list>

It is not possible to use <ion-item> until #18 is fixed.

Configuration attributes

date and time attributes

Choose which picker type is used. When neither is set, I assume both and use the datetime picker.

monday-first attribute

Set this if you want to have Monday as the first day of a week.

seconds attribute

By default, in the time picker, I allow to change only hours and minutes. Set this attribute to use also seconds.

am-pm attribute

By default, in the time picker, I use 24-hour clock. Set this attribute to change it to 12-hour clock.

month-step, hour-step, minute-step and second-step attributes

By default, when any caret button is tapped, I add or subtract 1 particular unit. Set these attributes to change it to anything you want.

title and sub-title attributes

Configure the title and sub title of the popup with the picker.

HINT: Use data-title instead of title if you are going to use the app in the desktop browser to prevent leaking of the text into a mouseover tooltip.

button-ok and button-cancel attributes

Configure the text of buttons at the bottom of the picker.

only-valid attribute

Disable/Enable calendar days according to type and date range specified.

only-valid="{'after': '2016-04-09'}"
only-valid="{'after': 'today', 'inclusive': true}"
only-valid="{'outside': {'initial': '2016-04-09', 'final': '2016-06-15'}, 'inclusive': true}"

Types supported: 'after', 'before', 'between' and 'outside'. If you want to include the day specified, set 'inclusive' property to true.

To combine rules, just pass an array and it should do the trick. Rules are complementary (treated with AND, not OR), it means that a date will be available only if it matches all the constraints you pass.

only-valid="[{'after': '2017-01-12'}, {'outside': {'initial': '2017-01-19', 'final': '2017-01-29'}}, {'outside': {'initial': '2017-02-19', 'final': '2017-02-29'}}]"

Internationalization & customization factory

Simple internationalization & customization options. Inject the $ionicPickerI18n factory into your code and set the localized strings and button classes.

weekdays key

Array of weekdays abbreviations. 0 is Sunday. If moment is installed, I try to get localized data from it, otherwise English ones are used as default.

months key

Array of months names. 0 is January. If moment is installed, I try to get localized data from it, otherwise English ones are used as default.

ok and cancel keys

Default, global labels of the buttons at the bottom of the picker.

okClass, cancelClass and arrowButtonClass keys

Custom space-delimited classes applied to the buttons at the bottom of the picker.

angular.module("myApp")
  .run(function($ionicPickerI18n) {
    $ionicPickerI18n.weekdays = ["Нд", "Lu", "Út", "Mi", "To", "금", "Sá"];
    $ionicPickerI18n.months = ["Janvier", "Febrero", "März", "四月", "Maio", "Kesäkuu", "Červenec", "अगस्त", "Вересень", "Październik", "Νοέμβριος", "డిసెంబర్"];
    $ionicPickerI18n.ok = "オーケー";
    $ionicPickerI18n.cancel = "Cancelar";
    $ionicPickerI18n.okClass = "button-positive";
    $ionicPickerI18n.cancelClass = "button-stable";
    $ionicPickerI18n.arrowButtonClass = "button-positive";
  });

Daylight saving time

The datetime picker is using Date object with your browser's timezone, including any DST. When you change the date, hour, minute, or second, which sets the time to an invalid value because of moving from 2:00 to 3:00 at the beginning of DST, the time is automatically adjusted to a valid value. On the other hand, when the DST ends, I do NOT take the inserted hour into consideration, but this may be fixed in the future.

ion-datetime-picker's People

Contributors

asikdevel avatar edmondchui avatar georapbox avatar gibujin avatar katemihalikova avatar lgrignon avatar przemkow avatar vijaybhere 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

ion-datetime-picker's Issues

numeric keyboard doesn't show

According to my pull request on android input types for hours, minutes and seconds doesn't show numerical keyboard. I tested this problem on android 5.0.1 with webview 37.0.0.0, android 4.4.4 with webview 32 and emulated android 6.0 with webview 44.0.0.0
Google says that android doesn't use pattern tag for providing keyboard so it would be nice to find other solution to show proper keyboard on all platforms.

Locale issue when selecting only time

My project is built upon ionic, and the code in html is as follows:

<button class="button button-small button-light" time ion-datetime-picker ng-model="s"> text:{{s}} </button>

When I select a time via datetime-picker, it outputs "text:"1899-12-31T14:13:00.000Z"", which should be "2016-08-09T15:13.00.000Z". The date picker has the same problem. Could anyone help me out with this sort-of locale problem? Thanks.

Problem loading "picker-popup.html"

After installing the "0.2.1" version with bower install, i had a path error : "localhost:3000/lib/ion-datetime-picker/src/picker-popup.html not found", so i modified "ion-datetime-picker.min.js" file where i changed templateUrl from "lib/ion-datetime-picker/src/picker-popup.html" to "picker-popup.html" and i worked perfectly.
Please make sure to solve this issue.
e.showPopup=function(){t.show({templateUrl:"picker-popup.html",title:e.title||"Pick "+(e.dateEnabled?"a date":"")+(e.dateEnabled&&e.timeEnabled?" and ":"")+(e.timeEnabled?"a time":"")

Integration with Angular-Formly

I'm trying to use your excellent component within a custom template in Angular-Formly but I can't do it. I'm not sure what I should call on the "onclick" event to show your component. Any suggestions?
(seasoned developer but very new to both Ionic and Angular-Formly :) )

Thanks !

Large font makes Mo (Monday) and We (Wednesday) wrap

On my Samsung S4 running Android 5.0.1, when I set my system font size to "Large", the calendar view wraps the text for Monday and Wednesday such that the "M" appears on one line and "o" appears on the next.

Could the overall width be increased slightly to avoid this odd result?

Thanks

Using datetime-pick to submit as a text value in html forms

Hi, I want to show the text value of {{DOB| date: "yyyy-MM-dd"}} in my form after clicking the dates on the calendar, so when I press submit, my controller will be able to get the string format to sent to backend servlets for processing. However the current the value does not show in the UI after selecting the date on the calendar. Any idea how to solve it?

How can i display the value in form to submit?

<<---register.html---->>
<label class="item item-input " id="register-input19"> <span class="input-label">DOB</span> <input type="tel" ion-datetime-picker date ng-model="DOB" value="{{DOB| date: 'yyyy MM-dd'}}" > </label>

<<---controller.js---->>`.controller('registerCtrl', function($scope, $http, $state, $ionicPickerI18n) {

    $scope.DOB = new Date();
    $ionicPickerI18n.weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
    $ionicPickerI18n.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    $ionicPickerI18n.ok = "Select";
    $ionicPickerI18n.cancel = "Cancel";

Time picker increment of 2 in mobile

Hi,

I have an issue with the framework, when I run in ionic serve everything is good, but if I run it on phonegap I have the picker who increment my step twice.

Do you have any idea why I have this issue ?

Thanks in adance for your answer

how to get value in a controller ?

Hi ,

I can't get the value in a controller while using $scope.datetimeValue .
Can you tell me how to do ?

<label class="item item-icon-right" ion-datetime-picker ng-model="datetimeValue">
                        <i class="icon ion-ios-grid-view-outline positive"></i>
                        Departure Date/Time
                        <strong>{{datetimeValue| date: "yyyy-MM-dd H:mm"}}</strong>
                     </label>

Thank you very much !

keep getting "Cannot GET /picker-popup.html?"

Hey guys, thanks for the awesome project.
I try it by the instructions , but i keep getting this error, "Cannot GET /picker-popup.html?",
so why my project keep to fetch template /picker-popup.html while your demo not?

only-valid attribute is Not taking value From Any Variable

As I am trying to select date from particular Interval of days , It is working with hard coded value to only-valid attribute And not with the value in variable. My code is as follows

woking==>

<div class="col" ion-datetime-picker date  ng-model="date" placeholder="dd/mm/yyyy" only-valid="{'between': {'initial': '2016-7-01', 'final': '2016-10-30' }, 'inclusive': true}" ng-change="setTime()"></div>

Not working==>

<div class="col" ion-datetime-picker date  ng-model="date" placeholder="dd/mm/yyyy" only-valid="{'between': {'initial': '{{date1}}', 'final': 'date2' }, 'inclusive': true}" ng-change="setTime()"></div>

Change Text "Pick a date and a time"

Hi! First of all my compliments for your awesome directive!
How can i change the text "Pick a date and a time"?
I Would to change it in Italian Language.
I tried with $ionicPickerI18N but it does not work. I tried to add an attribute title in the directive ion-datetime-picker but still nothing!
Any suggestion for this issue? Thanks!

Move focus to next time field

After entering a value of 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, or 12 into the hour field, focus should automatically move to the minute field so that the user doesn't have to click "Next" or manually select the minute field. The only value that would require pressing "Next" or manually selecting the minute field is a value of "1". The user could avoid this by entering a zero before the 1.

Similarly entering a value in the minute or second field, after entering any value 7 thru 59 the next field should automatically gain focus. Entering a value of 1 thru 6 would require the user to press "Next" or manually select the next field. The user could avoid this by entering a zero before the 1 thru 6.

Select on focus

In the time fields, it would be nice if the existing numbers would be selected when the field gains focus. This would allow the user to immediately start typing the new value without having to delete or select the old value.

Cant seem to get the selected time value

Hi im trying to get the selected time so for e.g.:
The user changes time to 05:10 in the popup and clicks ok, i want to be able to get the 05:10.
I tried testing with simple ionic popup in the ion-datetime-picker.min.js file so that i can know which line of code handles the ok onclick event. However i still cant find it after several attempts.

Does anyone know how to do it?
Any help is much appreciated. Thank you.

The ui doesnt update

Everything works fine in browser, but when run it on Android device, I can see the value is changed in chrome://inspect/#devices but not the ui (the input in android device).

Any idea, please?

Year not showed in Internet Explorer

Hello! First of all, I want to be grateful with all of you for this work and help, it's quite useful for developers.

I'm using ion-datetime-picker and I don't have any problems in Firefox and Chrome, but when I use it IE10, I'm able to open the calendar but the year is not displayed. If I click inside the box the year appears but a little bit cut.

I include a screen capture with the appearance.

sample

Do you know how to fix this error? Thanks a lot!

Error just when navigating to the page that used ion-datetime-picker

Hi,
I always get this error when I navigate to the page that used this plugin:
Error: [$compile:nonassign] Expression 'undefined' used with directive 'ionDatetimePicker' is non-assignable!

I implement this in my html page:
`



Arrived Time


{{task.arrivalRealization | date: "yyyy-mm-dd H:mm:ss"}}


`

Is there anything I need to change? Thanks.

month jumps to july when current date is 31st of may

the date in the field from which the picker is triggered is the 31st of may - when we open the picker, and click on the arrow to go to the next month, we end up in july instead of june :) reproduced on 2 different codebase

Having Two directives in same page.

Can I have 2 directives in same page and second picker's start date should be greater than the date that has been selected from first picker. How can I achieve this

Any way to set a calculated max date using between?

Hi,

using between how can I set a calculated max date ($scope.maxDate calculated and set in the controller) for the final value? 'final': 'maxDate' or 'final': '{{maxDate}}' is not working.

e.g.
<div class='item' ion-datetime-picker am-pm only-valid="{'between': {'initial': 'today', 'final': 'maxDate'}, 'inclusive': true}" title="'From Date/Time'" ng-model="event.fromDate">

controller.js

//maxDate set to 180 days from today
  $scope.maxDate = new Date(new Date().setDate(new Date().getDate()+180));

directive not working in ng-repeat

when ion-datetime-picker is used inside a ng-repeat loop the directive does not fire the element clcik event. Is it possible to make it working? (i'm new to angular)

Not Working For Text Field in Android

Hello,

I am using ion-datetime-picker and it's nice. But It is not working for Text Box in my android mobile.
Please help me to solve this issue.

Thank You

Open the popup with with different current date information

Hi,
First, I want to thank you for your plugin, it is very cool.
My problem: I want to open the datetime popup with the date, I have already set and not the current date and hour.

For example, my ng-model is 2016-04-09T15:27:47+02:00. When I open the popup, I still have the current date info selected.
Is there a way to set the correct date if the ng-model is contains a date ?
Thx

Change bindings from = to @

For some reasons I'm having some difficulties to get text values inside the directive scope. Once I have changed the binding method from bidirectional "=" to one-way text binding "@" it works as expected.

Firefox

Input Elements are not being filled with the time /date that is being set by the datetime picker.
Increasing the Date and Time works its just not showing up in the input elements of the popup

Getting 2 hours less than I want

Hi. I'm trying to set a value for hours but when I send that info to my API I always store 2 hours less than I want.

This is the piece of code:
<ion-list> <div class="padding" ion-datetime-picker ng-model="new.date_trip"> Fecha de salida <strong>{{new.date_trip| date: 'd MMM y @ HH:mm' : 'UTC + 2'}}</strong> <span ng-if="!new.date_trip">(click aquí para selecionar)</span> </div> </ion-list>

In the Ionic App it sees ok, but the in the Database is not stored as I want.

Thanks in advance

Datepicker inside a modal window causes modal to close

Hey,

I have an issue in my app, i have 2 inputs in which i'm getting the values of your datepickers but when i pick a date too quickly and then try to click on the other input field then it causes my current modal to close itself.

I've checked online for a quick fix but nothing seems to match my current problem. Maybe adding some setTimeOut on the Ok button validation will fix the problem but that is not the best way to handle things in my opinion.

Looking forward to hear if you got the same problem at some point

wiredep issues

Hey looks like the current bower.json isn't playing nice with wiredep using gulp as the task runner.
I had a quick look and the main and dependencies are there so I'm not sure how to fix this one with overrides.

Could be a problem with my task here's the code anyways

gulp.task('wire-vendor', function() {
gulp.src('./www/index.html')
.pipe(wiredep())
.pipe(gulp.dest('./www'));
});

gulp.task('wire-app', function() {
var target = gulp.src('./www/index.html');
var sources = gulp.src(['./www/js//*.js', './www/resources//*.css'], {read: false});
return target.pipe(inject(sources, {relative: true})).pipe(gulp.dest('./www'));
});

gulp.task('wiredep', ['wire-vendor','wire-app']);

Bug, Month text in month drop down list doesn't update

On android 5.0 Webview 37 (HUAWEI ALE-L21) i found a problem with refreshing month name in month drop down list. You can trigger this problem using steps bellow:

  1. Open datetime-picker
  2. Click on month drop down list
  3. Chose month from list (for instance December)
  4. App will change its calendar view to chosen month(December) but in select label you still see previous month name
  5. Chose different day in new month
  6. Calendar will mark chosen day with blue background and update month name in select label to current one (December)

I also checked it on other device (Samsung GT-I9060I, android 4.4 with webview 32) and there everything works fine...

Editing Minute Input field not behaving as in demo - Very weird Behaviour

First of all, Thanks for this awesome plugin.

The issue i am facing is easily understandable as below. I have not tested this issue on iOS yet. But on android i am facing this issue each time and on different devices with different android versions. I am also not facing this issue on desktop browser when running app through 'ionic serve' command.

  1. I opened time picker and tap on minute input field, My cursor is in last position.
    1
  2. I typed number 7 as in below screenshot

2

  1. Then i typed number 8 and suddenly before i can see '078' it changed to some garbage value as in below screenshot and stays as it is and after focus out it changed to '07'. It behaves similar if i try to type number below '60' and doesn't work at all as expected.

3

I have tried your demo on multiple devices and also on ionic view app and demo works perfectly.
But It doesn't work on my android devices and tablet.

The one major and main thing that is different in my android build is webview.

I am neither using default 'webview' nor 'crosswalk'. Instead i am using' webview+' provided by Cocoon.io and is only avaiable through Cloud Build and not as open source plugin.

What could be reason 'webview+' or some timing related issues in plugin code(less likely for me) or something else?

Can you pls provide your valuable feedback or solution for this issue?

Not Working with IOS Simulator and iPhone

Hi,

Thanks for developing a very useful plugin. It working fine with ionic server and even its working properly in my android but not working with ios.

I am too much confused how to solve this issues.

In ios date picker model is appear but when i am clicking on Ok button date time value didnt fill in my input.

Kindly help me and thanks in advance.

Here is my code
<input type="text" placeholder="e.g 25-12-2016 14:00" ion-datetime-picker id="interview_date_time" name="interview_date_time" ng-model="datetimeValue" readonly="readonly" value="{{datetimeValue| date: 'yyyy-MM-dd H:mm'}}" required="required" />

Enhancement - Events

There should be events such as onChange and inter operability with forms so that form validations can be performed where date time picker is used.
Suggested event types: on-change, on-tap

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.