3

I've found how to attach jquery datepicker to input element (like here) using knockout custom binding, but I would like to have a label with selected day name.

Like in jquery datepicker we got altField and altFormat that we can set to 'dddd' and get day name, is any elegant solution with jquery and knockout, because jquery can only populate altField, and not .

Also is there an option to initially bind input field with today's date in this format 'dd/mm/yy'?

I've also setup fiddle with test example here.

var ViewModel = function(){
    var self = this;
    self.date= ko.observable(new Date());
};

ko.applyBindings(new ViewModel());

$(function(){
    $('#dp').datepicker({minDate:0, dateFormat: 'dd/mm/yy'});
});

<div>
    <input id="dp" data-bind="value: date, valueUpdate: 'keyup'" />
    <p>Day in week: <strong data-bind="text: date"></strong></p>
</div>
Community
  • 1
  • 1
Juvastyle
  • 75
  • 1
  • 7

1 Answers1

1

You're mixing native jquery and knockout. Never use jQUery directly from your viewmodels, its bad practice. Have a look at my binding here

https://github.com/AndersMalmgren/Knockout.Bindings

Example http://jsfiddle.net/H8xWY/7/

Add dateformat to options:

<input data-bind="datepicker: date, datepickerOptions: { minDate: new Date(), dateFormat: 'dd/mm/yy' }" />
Anders
  • 17,306
  • 10
  • 76
  • 144