knockout.js - How to bind Bootstrap datepicker with Knockout within Durandal framework -
i wanted avoid lumping onto existing question.
so i'm trying use jsfiddle within durandal framework have main.js configured require bindings (please notice observable: true):
define(['durandal/system', 'durandal/app', 'durandal/viewlocator', 'modules/logger', 'modules/bindings', 'modules/hubservice'], function (system, app, viewlocator, logger, bindings, hubservice) { app.configureplugins({ router: true, dialog: true, widget: true, observable: true });
i've set bindings.js composite binding handler so:
composition.addbindinghandler('datepicker', { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var unwrap = ko.utils.unwrapobservable; var datasource = valueaccessor(); var binding = allbindingsaccessor(); var options = { keyboardnavigation: true, todayhighlight: true, autoclose: true, format: 'mm/dd/yyyy' }; if (binding.datepickeroptions) { options = $.extend(options, binding.datepickeroptions); } $(element).datepicker(options); $(element).datepicker('update', datasource); $(element).on("changedate", function (ev) { var observable = valueaccessor(); if ($(element).is(':focus')) { // don't update while user in field... // instead, handle focus loss $(element).one('blur', function (ev) { var dateval = $(element).datepicker("getdate"); observable(dateval); }); } else { observable(ev.date); } }); //handle removing element dom ko.utils.domnodedisposal.adddisposecallback(element, function () { $(element).datepicker('remove'); }); }, update: function (element, valueaccessor) { var value = ko.utils.unwrapobservable(valueaccessor()); $(element).datepicker('update', value); } });
while works in jsfiddle, throws error when using code in durandal framework.
the view comes , can use datepicker throws error on following line:
observable(dateval);
anyone have clue how work durandal's usage of observables?
Comments
Post a Comment