Cordova Plugin for showing a native date, time or datetime picker.
cordova plugin add skwas-cordova-plugin-datetimepicker
or for latest
cordova plugin add https://github.com/skwasjer/skwas-cordova-plugin-datetimepicker.git
- Android 4.4 and higher
- iOS 10 and higher
- Cordova 7
show(options)
Show the plugin with specified options.
show(options, successCallback, errorCallback)
Show the plugin with specified options and callbacks.
This was the original way to call the plugin, and is kept for compatibility.
Note: The
successCallback
anderrorCallback
respectively will be ignored if thesuccess
orerror
callback is provided on theoptions
argument.
Name | Type | Default | Description |
---|---|---|---|
theme | int | Theme_DeviceDefault_Dialog | android.R.style theme |
is24HourView | boolean | true | Use a 24 hour clock |
On Lollipop and upwards the date and time pickers changed to calendar and radial pickers. If you want to use spinners (for example to use
minuteInterval
), use a built-in android.R.style theme that shows a date and time picker with spinners or read up here how to customize this.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var myDate = new Date(); // From model.
cordova.plugins.DateTimePicker.show({
mode: "date",
date: myDate,
allowOldDates: true,
allowFutureDates: true,
minDate: new Date(),
maxDate: null,
minuteInterval: 15,
locale: "EN",
okText: "Select",
cancelText: "Cancel",
android: {
theme: 16974126, // Theme_DeviceDefault_Dialog
is24HourView: true
},
success: function(newDate) {
// Handle new date.
console.info(newDate);
myDate = newDate;
},
cancel: function() {
console.info("Cancelled");
},
error: function (err) {
// Handle error.
console.error(err);
}
});
}
hide()
Hide the date time picker.
If the picker is currently being shown and a cancel-callback was provided in the options, the callback will be called when the picker is hidden.
cordova.plugins.DateTimePicker.hide();
For a list of all changes see here.