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 |
|
7 | Ion2 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 |
|
10 | Simulate 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
|
12 | only 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.
|
14 | This one helps to solve these problems.
|
15 |
|
16 | **Note: [MomentJS](http://momentjs.com/) requred for using some features of the package**
|
17 |
|
18 | Github: [https://github.com/byzg/ion2-datetime-picker](https://github.com/byzg/ion2-datetime-picker)
|
19 |
|
20 | NPM: [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
|
29 | Check out the live demo here: [https://raychenfj.github.io/ion-multi-picker/](https://raychenfj.github.io/ion-multi-picker/)
|
30 |
|
31 | ## Supported Version
|
32 |
|
33 | Ionic2 2.0.0-rc.3
|
34 |
|
35 | Ionic CLI 2.1.12 -->
|
36 |
|
37 |
|
38 | ## Installation
|
39 | ```
|
40 | npm install ion2-datetime-picker --save
|
41 | ```
|
42 |
|
43 | ## Usage
|
44 | 1.Import MultiPickerModule to your app/module.
|
45 | ```Typescript
|
46 | import { 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 | })
|
70 | export class AppModule {}
|
71 | ```
|
72 | 2.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 |
|
82 | Like other ionic components, you can use `[formControl]` to bind your data.
|
83 |
|
84 | ```typescript
|
85 | import { FormBuilder, FormGroup } from '@angular/forms';
|
86 | ...
|
87 | constructor() {
|
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 |
|
101 | Set `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/) | all | DD.MM.YYYY HH:mm |
|
117 | |pickerFormat| Format of picking data. **Note: now supports only months** | String | [moment formats](http://momentjs.com/docs/#/displaying/format/) | date | `displayFormat` |
|
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. Note: Monday is the first day and Sunday is a seventh day | 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 | | dateContext | By default if initail model value is given then date of min and max setups to date of this model value. But if initail model value is given is not given then date of min and max setups to current date. Set dateContext attribute to change it | ISO 8601 String or moment.Moment | | time | |
|
126 |
|
127 | ## Exceptions
|
128 | If for some reason, all the possible
|
129 | values of the column are non-valid, this exception is raised:
|
130 | * `Ion2 datetime picker: column "<column.name> " should have at least one option` -
|
131 |
|
132 | ## Utils
|
133 | You can use some utils methods:
|
134 | ```typescript
|
135 | import { MultiPickerUtils } from 'ion2-datetime-picker';
|
136 |
|
137 | let variable = MultiPickerUtils.minuteRound('2016-12-10T11:32:44+03:00', 15);
|
138 | ```
|
139 |
|
140 |
|
141 | * minuteRound(val: string\|moment.Moment, rounding: number): moment.Moment
|
142 |
|
143 | Returns nearest from below moment for *val* with minutes that multiple for *rounding*
|
144 |
|
145 | ## Contribution
|
146 |
|
147 | Welcome issue report, PR and contributors. Help me improve it.
|
148 |
|
149 | Fork and `git clone` this project,
|
150 | most code for the multi picker is under `src/app/components/multi-picker`.
|
151 |
|
152 | The unit test framework is karma + webpack + jasmine. And e2e test is protractor.
|
153 |
|
154 | Add your unit test and use `npm test` to start karma.
|
155 |
|
156 | Debug your unit test using `npm run test-watch` and open `http://localhost:9876/debug.html`
|
157 |
|
158 | Add your e2e test, run `ionic serve` and then in another terminal use `npm run e2e` to run protractor.
|
159 |
|
160 | You can also add your use case in the `app/pages`.
|
161 |
|
162 | Finally, send me a `PULL REQUEST`.
|
163 |
|
164 | ##### Build
|
165 |
|
166 | `gulp default`
|
167 |
|
168 | ## License
|
169 | MIT
|