UNPKG

5.59 kBMarkdownView Raw
1# Ion2-datetime-picker
2
3
4[![Dependency Status](https://david-dm.org/byzg/ion2-datetime-picker.svg)](https://david-dm.org/byzg/ion2-datetime-picker) [![devDependencies Status](https://david-dm.org/byzg/ion2-datetime-picker/dev-status.svg)](https://david-dm.org/byzg/ion2-datetime-picker?type=dev) [![npm version](https://badge.fury.io/js/ion2-datetime-picker.svg)](https://badge.fury.io/js/ion2-datetime-picker) [![npm download](https://img.shields.io/npm/dm/ion2-datetime-picker.svg)](https://www.npmjs.com/package/ion2-datetime-picker)
5
6
7Ion2 Datetime Picker--An Ionic2 Custom Datetime Picker Component based on
8[ion-multi-picker](https://github.com/raychenfj/ion-multi-picker) by [raychenfj](https://github.com/raychenfj)
9
10Simulate IOS date and time column pickers by ionic2 picker. Default
11[Ionic DateTime Component](http://ionicframework.com/docs/v2/api/components/datetime/DateTime/) work with
12only independent columns that has some validation problems. Also there is
13[min and max issue](https://github.com/driftyco/ionic/issues/6850) with time validation.
14This one helps to solve these problems.
15
16**Note: [MomentJS](http://momentjs.com/) requred for using some features of the package**
17
18Github: [https://github.com/byzg/ion2-datetime-picker](https://github.com/byzg/ion2-datetime-picker)
19
20NPM: [https://www.npmjs.com/package/ion2-datetime-picker](https://www.npmjs.com/package/ion2-datetime-picker)
21<!---
22## Preview
23### Picker with Independent/ Dependent Columns
24
25![Picker with Independent Columns](https://github.com/raychenfj/ion-multi-picker/blob/master/img/independent.gif?raw=true)
26![Picker with Dependent Columns](https://github.com/raychenfj/ion-multi-picker/blob/master/img/dependent.gif?raw=true)
27
28## Demo
29Check out the live demo here: [https://raychenfj.github.io/ion-multi-picker/](https://raychenfj.github.io/ion-multi-picker/)
30
31## Supported Version
32
33Ionic2 2.0.0-rc.3
34
35Ionic CLI 2.1.12 -->
36
37
38## Installation
39```
40npm install ion2-datetime-picker --save
41```
42
43## Usage
441.Import MultiPickerModule to your app/module.
45```Typescript
46import { MultiPickerModule } from 'ion2-datetime-picker';
47
48@NgModule({
49 declarations: [
50 MyApp,
51 AboutPage,
52 ContactPage,
53 HomePage,
54 TabsPage,
55 ],
56 imports: [
57 IonicModule.forRoot(MyApp),
58 MultiPickerModule //Import MultiPickerModule
59 ],
60 bootstrap: [IonicApp],
61 entryComponents: [
62 MyApp,
63 AboutPage,
64 ContactPage,
65 HomePage,
66 TabsPage,
67 ],
68 providers: []
69})
70export class AppModule {}
71```
722.Add ion-multi-picker to your html template.
73
74```html
75 <ion-item>
76 <ion-label>Simple TimePicker</ion-label>
77 <ion-multi-picker item-content></ion-multi-picker>
78 </ion-item>
79```
80**Note: Don't miss the `item-content` attribute**
81
82Like other ionic components, you can use `[formControl]` to bind your data.
83
84```typescript
85import { FormBuilder, FormGroup } from '@angular/forms';
86...
87constructor() {
88 this.formGroup = new FormBuilder().group({
89 time: [moment().format()]
90 });
91}
92```
93
94```html
95 <ion-item>
96 <ion-label>Default Value</ion-label>
97 <ion-multi-picker item-content [formControl]="formGroup.controls.time"></ion-multi-picker>
98 </ion-item>
99```
100
101Set `type` to `date` to use datepicker.
102
103```html
104 <ion-item>
105 <ion-label>Disabled Picker</ion-label>
106 <ion-multi-picker item-content type="date" [formControl]="formGroup.controls.date"></ion-multi-picker>
107 </ion-item>
108```
109
110## Attributes
111
112| Attribute | Description | Data type | Values | Picker type | Default|
113|-----------|-------------|-----------|--------|-------------|--------|
114|item-content|**Required**, add this attribute so that this custom component can be display correctly under `ion-item` tag| - | - | all | - |
115|type| Sets waht to use: date- or timepicker | String | date or time| - | time |
116|displayFormat| Format of picked data | String | [moment formats](http://momentjs.com/docs/#/displaying/format/) | time | HH:mm |
117||||| date | DD.MM.YYYY |
118| min | Validation minimum attribute | ISO 8601 String or moment.Moment | | time | Beginning of the year, which precedes the current 2 years |
119| max | Validation maximum attribute | ISO 8601 String or moment.Moment | | time | End of the year that follows the current 2 years |
120| minuteRounding | Minutes will be equal this one or aliquot | String or Number | 60 must be divisible by this | time | 1 |
121| cancelText | Text of picker cancel button | String | | all | Cancel |
122| doneText | Text of picker done button | String | | all | Done |
123| weekends | Numbers of days of week that should be disabled on datepicker | String or Array of string | E.g.: ['6', '7'] | date | [] |
124| filterDays | Function like (days, month, year)=> that should return array of day numbers that should NOT be disabled in given month and year | Function | E.g.: (days, month, year)=> days | date | Lodash identity |
125
126## Exceptions
127If for some reason, all the possible
128 values of the column are non-valid, this exception is raised:
129* `Ion2 datetime picker: column "<column.name> " should have at least one option` -
130
131## Contribution
132
133Welcome issue report, PR and contributors. Help me improve it.
134
135Fork and `git clone` this project,
136most code for the multi picker is under `src/app/components/multi-picker`.
137
138The unit test framework is karma + webpack + jasmine. And e2e test is protractor.
139
140Add your unit test and use `npm test` to start karma.
141
142Add your e2e test, run `ionic serve` and then in another terminal use `npm run e2e` to run protractor.
143
144You can also add your use case in the `app/pages`.
145
146Finally, send me a `PULL REQUEST`.
147
148## License
149MIT