Coder Social home page Coder Social logo

magaliegimenes / ion-datetime-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from katemihalikova/ion-datetime-picker

0.0 1.0 0.0 370 KB

Date and/or time picker for awesome Ionic framework

License: MIT License

JavaScript 66.76% HTML 22.16% CSS 11.08%

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 and cancelClass 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";
  });

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

katemihalikova avatar georapbox avatar asikdevel avatar lgrignon avatar gibujin avatar przemkow avatar edmondchui avatar

Watchers

 avatar

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.