Custom Fork of the iOS Datepicker From Phonegap Plugins
Essential changes are:
- Javascript part of the datePicker plugin has been defined as an cordova module
- DatePicker was added support for value change event callback.
- DatePicker was added hide method.
- DatePicker was added prev/next buttons and optional callbacks.
- DatePicker layouts properly both in portrait and landscape mode.
-
Add the
src/DatePicker.h
andsrc/DatePicker.m
files to your Plugins folder in your project. -
Add the
src/DatePicker.js
files to yourwww
folder on disk, and add reference to theDatePicker.js
files as <script> tags in your html file(s) -
Add an entry for the plugin in the config.xml
Pre 2.8.0
<plugins> <plugin name="DatePicker" value="DatePicker" /> </plugins>
Post 2.8.0 and up
<feature name="DatePicker"> <param name="ios-package" value="DatePicker"/> </feature>
var datePicker = cordova.require("cordova/plugin/datepicker");
var options = {
date: new Date(),
mode: 'date',
allowOldValues: true,
allowFutureValues: true,
visibility: 'auto',
onChange: function (date) {
// on datepicker value change
},
onDismiss: function (date) {
// on datepicker dismiss
},
onPrev: function () {
// on datepicker action sheet previous button clicked
},
onNext: function () {
// on datepicker action sheet next button clicked
}
};
datePicker.show(options);
The options are:
-
date:
The default date to display if none provided it will automatically use now. -
mode:
The granularity mode either date or datetime, datetime has extended granularity for hours, time and seconds. Defaults to date, if an empty string the granularity will be date + time. -
allowOldValues:
Wether to allow older values than the date provided, default true. -
allowFutureValues:
Wether to allow future values than the date provided, default true. -
visibility:
Howto to display prev/next buttons, auto | visible | hidden- If visibility state set to
auto
, only display prev / next buttons if one of theonPrev
/onNext
functions set, otherwise display none - If visibility state set to
visible
set, both prev / next buttons will be display always, still the enabled state of the buttons will only be display if a correspondentonPrev
/onNext
state function has been provided. - If visibility state set to
hidden
, both prev / next buttons will not be visible regardless wether theonPrev
/onNext
functions have beeen provided or not.
- If visibility state set to
-
onChange:
optional callback for when the datepicker changes its value, the selected date value will be provided back as an native js date value. -
onDismiss:
required callback for when the datepicker has been dismissed, the selected date value will be provided back as an native js date value. -
onPrev:
optional callback to enable the ui controled segmented prev button, and to be called when it has been clicked. -
onNext:
optional callback to enable the ui controled segmented next button, and to be called when it has been clicked
All options besides the required onDismiss callback are optional.
Run the Example project to see a live example, plus simple usage of the DatePicker plugin.