BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

Datepicker fails when convertors in use #409

Closed naxellar closed 5 years ago

naxellar commented 5 years ago

I am using datepicker control from jQuery UI tag controls library.

{^{datepicker date _dateFormat="dd/mm/yy" convert="toDateString" convertBack="toWcfDate"}}
  <input type="text" value=""/>
{{/datepicker}}

toDateString converter returns date in datepicker format, toWcfDate converter gets datepicker format and returns ASP.NET format (e.g. /Date(1198908717056-0700)/).

See JSFiddle demo

This code fails on 34 line of jsviews-jqueryui-widgets.js:

Uncaught TypeError: Cannot read property 'getRsc' of undefined
    at getConverter (jsviews-jqueryui-widgets.js:35)
    at init (jsviews-jqueryui-widgets.js:367)
    at i.init (jsviews.js:183)
    at y (jsviews.js:776)
    at Function.eval [as fn] (eval at H (jsviews.js:2426), <anonymous>:6:2)
    at O (jsviews.js:1743)
    at Function.M [as render] (jsviews.js:1593)
    at ge (jsviews.js:4908)
    at Function.ue [as link] (jsviews.js:4862)
    at window.onload ((index):54)
/// jsviews-jqueryui-widgets.js
...
function getConverter(tag, cvt) {
  return cvt + "" === cvt ? tag.tagCtx.contentView.getRsc("converters", cvt) : cvt;
}
...

Did I do something wrong or it is a bug? Thank you.

BorisMoore commented 5 years ago

Thank you for calling this out! You are right, that looks like a bug in the jsviews-jqueryui-widgets.js code.

I think the fix is to change that line to

function getConverter(tag, cvt) {
  return cvt + "" === cvt ? tag.tagCtx.view.getRsc("converters", cvt) : cvt;
}

Can you test in your environment that that works for you?

naxellar commented 5 years ago

Yes, it works, thank you.

BorisMoore commented 5 years ago

This has been fixed in the v1.0.0 release