Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8020957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:50:08+00:00 2026-06-04T21:50:08+00:00

When using jquery-ui custom bindings to add a datepicker to a text field it

  • 0

When using jquery-ui custom bindings to add a datepicker to a text field it only updates my model when I don’t use templates.

Simple JSFiddle demostration of problem

HTML:

<script type="text/html" id="datepicker-template">
        <span data-bind="text: $data"></span>
        <input type="text" data-bind="jqueryui: {widget:'datepicker'}, value: $data">
</script>

<h2>Witout templates</h2>
<div>
    <span data-bind="text: from"></span>
    <input type="text" data-bind="jqueryui: {widget:'datepicker'}, value: from">
    <span data-bind="text: to"></span>
    <input type="text" data-bind="jqueryui: {widget:'datepicker'}, value: to">
</div>
<h2>With template<h2>
<div data-bind="template: {name:'datepicker-template', foreach: dates}"></div>

JavaScript:

$(function(){
    var ViewModel = function(){
        this.from = ko.observable("from");
        this.to = ko.observable("to");
        this.dates = ko.observableArray([this.from, this.to]);
    };

    var viewModel = new ViewModel();               
    ko.applyBindings(viewModel);
});​

Feel like I’m missing something very simple.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:50:09+00:00Added an answer on June 4, 2026 at 9:50 pm

    Actually, the problem is reproducible in a simple example without the jQueryUI bindings. The problem has to do with the $data keyword inside of knockout templates.

    Apparently $data cannot be used for a two-way binding inside of a template. See this Google Groups thread for some commentary:

    If you have items: [“one”, “two”, “three”] or even
    [ko.observable(“one”), ko.observable(“two”), ko.observable(“three”)]
    within a foreach $data will be the raw value and KO has no way at
    that point to know how to write back to it. You need to use objects
    with properties
    , in the case that you need to read/write access to
    the value.

    So one way to get around this limitation is to create a simple ViewModel for your date objects:

    var DateViewModel = function (initialValue) {
        this.value = ko.observable(initialValue);
    };
    

    And then in your main ViewModel you could write:

    var ViewModel = function() {
        this.dates = ko.observableArray([
            new DateViewModel("from"),
            new DateViewModel("to")
        ]);
    };
    

    And your template would end up being something like this:

    <script type="text/html" id="datepicker-template">
        <span data-bind="text: value"></span>
        <input type="text" data-bind="value: value">
    </script>
    

    Example: http://jsfiddle.net/RjEnh/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a custom function using jquery validation framework, to help validating
I'm using jquery.validationengine.en.js to (custom )validate my form fields. For one field, I'm using
I am using jQuery's UI dialogs and I want to add a custom method.
I'm using jQuery UI: <script type=text/javascript src=/jscripts/jquery-1.4.min.js></script> <script type=text/javascript src=/jscripts/jquery-ui-1.8.2.custom.min.js></script> and IE7 (corporate rule!)
Using Jquery TableSorter, I am creating a custom parser to sort elapsed time <td>
I am using a custom jQuery slider to display some images and fade through
Using jQuery timepickr: http://archive.plugins.jquery.com/project/jquery-timepickr Having included these files: jquery-1.7.1.min.js jquery-ui-1.8.21.custom.min.js ui.timepickr.js And getting this
I am using jquery to create a custom dropdown with the code below. I
I'm using a custom jScrollPane and dynamically populate it using jQuery from a returned
We are using jQuery in our project. We have numerous custom javascript files in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.