Search code examples
jsviews

JSViews two way binding not working with datepicker


I'm using the sample jquery controls with jsviews found here: http://www.jsviews.com/#samples/tag-controls/datepicker/simple

The spinner works great with two way binding but the datepicker does not.

I've tried three variations on linking.

{^{datepicker sDate }}
    <input id="sDate" name="sDate" />
{{/datepicker}}

{^{datepicker sDate /}}

<input class="" data-link="{datepicker sDate}" type="text" name="sDate" id="sDate" />

The data being bound takes a asp.net json date, converts it to a js date with Moment, and adds it to the bound object. "sDate" therefore is a basic js date.

data.sDate = moment(data.StartDate).toDate();

What am I missing?


Solution

  • Take a look at http://www.jsviews.com/#samples/tag-controls/datepicker/with-converters - which uses Moment to convert.

    You can add a second datepicker - by repeating the following, for example:

    <div data-link="{datepicker date
         _dateFormat='dd/mm/y'
         convert='toDateString'
         convertBack='toWcfDate'
      }"></div>
    

    and you will see the two-way binding works, with the two datepicker staying in sync when you change either.

    See also the discussion here: https://github.com/BorisMoore/jsviews/issues/344#issuecomment-235405312