Search code examples
javascripthtmljsviews

JSViews visible link with converter doesn't work


I upgraded to the latest version of JsViews and it seems like something broke.

If I have a data-link like "visible{:property}", it works.

If I have a data-link like "visible{convert:property}", it does not work.

From what I can tell it seems like it looks early on in the process for the attr "visible" and changes it to "css-display". When I have a converter, though, in propertyChangeHandler it does this line

attr = linkCtx.attr || attr; // linkCtx.attr may have been set to tag.attr during tag instantiation in renderTag

That causes it to change attr back to "visible", and then in updateContent, the regex test for "css-" fails and it never sets the display property.

Am I missing something? Shouldn't this work?

I created a fiddle that shows what I am trying to do. In the non-working case, instead of setting display:none, it sets visible="false"

http://jsfiddle.net/4scbgjpx/2/

<script id="worksTempl" type="text/x-jsrender">
<div data-link="visible{:show}">
    <span data-link="name"></span>
</div>
</script>

<script id="failsTempl" type="text/x-jsrender">
<div data-link="visible{negate:show}">
    <span data-link="name"></span>
</div>
</script>

$.views.converters({
    "negate": function (val) { return !val; }
});

Solution

  • Yes, you are right - that was a bug. It has been fixed now (commit 58), and your jsfiddle now works correctly.