user1841310
user1841310

Reputation: 1

Knockout - display date format dd-MM-yyy but store the string as Date in viewmodel using jqm DateBox

I am new to knockout... I have the following problem. I am using jqm DateBox to set Date and knockout plugin to manage the viewmodel. I want to display date in the format dd-mm-yyyy (AS IS) but in the same time i want that the viewmodel stores not the date as string but as a Date(). Is this possible?
Thanks in advance!

Upvotes: 0

Views: 1393

Answers (2)

user1841310
user1841310

Reputation: 1

For info, this is the code:

ko.bindingHandlers.jqmDateBox = {
    'init': function (element, valueAccessor, allBindingsAccessor, context) {
        ko.utils.registerEventHandler(element, "change", function () {
            var observable = valueAccessor();
            observable($(element).data('datebox').theDate);
        });
    }
};

Upvotes: 0

Anders
Anders

Reputation: 17564

I've done this for the jQuery UI Datepicker, im guessing its similar with Mobile. From the init function of your custom datebox binding do

ko.utils.registerEventHandler(element, "change", function () {
    var observable = valueAccessor();
    observable($(element).datepicker("getDate"));
});

For e complete datepicker example see my collection of bindings https://github.com/AndersMalmgren/Knockout.Bindings

Upvotes: 1

Related Questions