Reputation: 1374
I am trying to use Lee Crossley's WP8 plugin-datetime-picker for the WP8 flavour of my Cordova app.
I already have iOS, Android and Fireos versions of the app running with their own datepicker plugins, but I'm struggling to get this version to work.
I instantiate the picker like so:
<input onclick="doDatePick(this)" readonly name="my-account-dob" id="my-account-dob" value="" class="required" />
And try to receive the input like this:
function doDatePick(elem) {
console.log('at doDatePick');
var onDateSelected = function (date) {
console.log('inside function');
alert(new Date(parseInt(date, 10)));
console.log(new Date(parseInt(date, 10)));
$(elem).val(DPgetNamedMonthDate(new Date(parseInt(date, 10))));
}
datetimepicker.selectDate(onDateSelected);
}
The datepicker is displayed, and 'at doDatePick' is logged. But when I confirm the new date in the datepicker, nothing else is logged and Visual Studio reports 'Failed to locate callback for id : DateTimePicker' in its output window. Needless to say, the input box isn't updated with my selected date.
I'm sure the Cordova project is set up correctly; I installed all the plugins I required and did a build before adding any code via Visual Studio. Other third party plugins, such as Chris Brody's SqlLite Plugin work fine.
Any advice greatly appreciated.
Upvotes: 1
Views: 1272
Reputation: 1280
I have reported the core issue to the Cordova team.
As a temporary workaround, the platforms\wp8\cordovalib\Commands\BaseCommand.cs
DetatchHandlers()
method could be replaced with:
public void DetachHandlers()
{
this.OnCommandResult = null;
this.OnCustomScript = null;
foreach (string callbackId in new List<string>(ResultHandlers.Keys))
{
if (!callbackId.ToLower().Contains("datetimepicker"))
{
RemoveResultHandler(callbackId);
}
}
}
I know it's a hack, but it will get you going. You could alternatively use an older version of Cordova.
Upvotes: 2
Reputation: 1241
I have solved this issue on github.
Simply I have saved the handler in selectDate
method of DateTimePicker.cs
class to read that back on ResultHandler
dictionary before DispatchCommandResult
.
public event EventHandler<PluginResult> mySavedHandler;
....
public void selectDate(string options)
{
....
if (ResultHandlers.ContainsKey(CurrentCommandCallbackId))
{
mySavedHandler = ResultHandlers[CurrentCommandCallbackId];
}
....
}
private void dateTimePickerTask_Completed(object sender, DateTimePickerTask.DateTimeResult e)
{
......
try
{
if (!ResultHandlers.ContainsKey(CurrentCommandCallbackId))
{
ResultHandlers.Add(CurrentCommandCallbackId, mySavedHandler);
}
.....
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result + ""));
}
}
Upvotes: 2