Struggling with inline jQuery DatePicker binding

250 views
Skip to first unread message

b...@roestudios.com

unread,
Dec 5, 2012, 9:35:19 PM12/5/12
to knock...@googlegroups.com
So I've been using a custom binding for the Date Picker, no problem. In switching to the inline version, however, things aren't working as smoothly. My input was already contained within a DIV, so I just adjusted decided to target the element's parent. The new custom binding as follows:

ko.bindingHandlers.datepicker = {
init: function(element, valueAccessor, allBindingsAccessor) {
var options = { dateFormat: 'mm/dd/yy', showButtonPanel: true, changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true };
$(element).parent().datepicker(options);
ko.utils.registerEventHandler($(element).parent(), "change", function() {
var observable = valueAccessor();
observable($(element).parent().datepicker("getDate"));
});
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).parent().datepicker("destroy");
});
},
update: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).parent().datepicker("setDate", value);
}
};

Now, this mostly works. What is no longer working are my month and year selection drop-downs. For some reason, they're totally borked. Everything else though works as expected.

Any idea what I can tweak to get this all humming along again?

zia...@gmail.com

unread,
Dec 6, 2012, 2:39:11 AM12/6/12
to knock...@googlegroups.com, b...@roestudios.com

b...@roestudios.com

unread,
Dec 6, 2012, 7:39:08 AM12/6/12
to knock...@googlegroups.com, b...@roestudios.com
Of course! Just skip the input altogether. Duh!

Thanks!

b...@roestudios.com

unread,
Dec 6, 2012, 5:53:05 PM12/6/12
to knock...@googlegroups.com, b...@roestudios.com, zia...@gmail.com
I was still having problems. Turns out an older verion of jQuery UI was to blame. :$

On Thursday, December 6, 2012 2:39:11 AM UTC-5, zia...@gmail.com wrote:
http://jsfiddle.net/ziaxdk/y6zJD/3/

Ken
Reply all
Reply to author
Forward
0 new messages