README.md 4.62 KB
Newer Older
李晓兵's avatar
李晓兵 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
# DatePicker Plugin for Cordova/PhoneGap 4.0 (iOS and Android and Windows)

This is a combined version of DatePicker iOS and Android and Windows plugin for Cordova/Phonegap 4.0.
- Original iOS version: https://github.com/sectore/phonegap3-ios-datepicker-plugin

- Original Android version: https://github.com/bikasv/cordova-android-plugins/tree/master/datepicker

New in 0.8.0 (Android Only):
- Android code refactored

- Option datetime added (default if mode is unknown), opening a new time dialog after setting the date

- Options okText and cancelText to define the labels for POSITIVE and NEGATIVE buttons

- Option todayText to set the label of a button that selects current date (date and datetime)

- Option nowText to set the label of a button that selects current time (time and datetime)

- Option is24Hour added


## Installation

- Local development workflow using [Cordova CLI](http://cordova.apache.org/docs/en/edge/)

```bash
cordova plugin add cordova-plugin-datepicker
```

- Local development workflow using [PhoneGap CLI](http://phonegap.com/install/)

```bash
phonegap local plugin add cordova-plugin-datepicker
```

- Cloud-based development workflow using [PhoneGap Build](http://build.phonegap.com)

```bash
<gap:plugin name="cordova-plugin-datepicker" source="npm" />
```


## Usage

```js
var options = {
    date: new Date(),
    mode: 'date'
};

function onSuccess(date) {
    alert('Selected date: ' + date);
}

function onError(error) { // Android only
    alert('Error: ' + error);
}

datePicker.show(options, onSuccess, onError);
```

## Options

### mode - iOS, Android, Windows
The mode of the date picker.

Type: String

Values: `date` | `time` | `datetime` (iOS, Windows only)

Default: `date`

### date - iOS, Android, Windows
Selected date.

Type: String

Default: `new Date()`

### minDate - iOS, Android, Windows
Minimum date.

Type: Date | empty String

Default: `(empty String)`

minDate is a Date object for iOS and a millisecond precision unix timestamp for Android, so you need to account for that when using the plugin.

### maxDate - iOS, Android, Windows
Maximum date.

Type: Date | empty String

Default: `(empty String)`

### titleText - Android
Label for the dialog title. If empty, uses android default (Set date/Set time).

Type: String | empty String

Default: `(empty String)`

### okText - Android
Label of BUTTON_POSITIVE (done button). If empty, uses android.R.string.ok.

Type: String | empty String

Default: `(empty String)`

### cancelText - Android
Label of BUTTON_NEGATIVE (cancel button). If empty, uses android.R.string.cancel.

Type: String | empty String

Default: `(empty String)`

### todayText - Android
Label of today button. If empty, doesn't show the option to select current date.

Type: String | empty String

Default: `(empty String)`

### nowText - Android
Label of now button. If empty, doesn't show the option to select current time.

Type: String | empty String

Default: `(empty String)`

### is24Hour - Android
Shows time dialog in 24 hours format.

Type: Boolean

Values: `true` | `false`

Default: `false`

### androidTheme - Android
Choose the theme of the picker

Type: Int

Values: `THEME_TRADITIONAL | THEME_HOLO_DARK | THEME_HOLO_LIGHT | THEME_DEVICE_DEFAULT_DARK | THEME_DEVICE_DEFAULT_LIGHT`

Default: `THEME_TRADITIONAL`

### allowOldDates - iOS
Shows or hide dates earlier then selected date.

Type: Boolean

Values: `true` | `false`

Default: `true`

### allowFutureDates - iOS
Shows or hide dates after selected date.

Type: Boolean

Values: `true` | `false`

Default: `true`

### doneButtonLabel - iOS
Label of done button.

Typ: String

Default: `Done`

### doneButtonColor - iOS
Hex color of done button.

Typ: String

Default: `#0000FF`

### cancelButtonLabel - iOS
Label of cancel button.

Type: String

Default: `Cancel`

### cancelButtonColor - iOS
Hex color of cancel button.

Type: String

Default: `#000000`

### x - iOS (iPad only)
X position of date picker. The position is absolute to the root view of the application.

Type: String

Default: `0`

### y - iOS (iPad only)
Y position of date picker. The position is absolute to the root view of the application.

Type: String

Default: `0`

### minuteInterval - iOS
Interval between options in the minute section of the date picker.

Type: Integer

Default: `1`

### popoverArrowDirection - iOS
Force the UIPopoverArrowDirection enum.
The value `any` will revert to default `UIPopoverArrowDirectionAny` and let the app choose the proper direction itself.

Values: `up` | `down` | `left` | `right` | `any`

Type: String

Default: `any`

### locale - iOS
Force locale for datePicker.

Type: String

Default: `en_us`

## Requirements
- Cordova 3.0+
- iOS 6.0+
- Android 2.3+