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

If the selected value of a data-linked <select> is set prior to adding options, selection is not always established correctly #449

Closed johan-ohrn closed 3 years ago

johan-ohrn commented 3 years ago

(Sorry for the poor title)

I have a tag that is using linkedElement. The selected value is set before the actual values are available. After the values are rendered I'm expecting the select element to have it's value set to the selected value. Here is a fiddle to demonstrate the issue. The tag t1 has a data-link attribute set manually while the tag t2 uses linkedElement. If the values are available before the tag renders then it work correctly.

I followed the code and this method in jquery.views.js is called:

function bindDataLinkTarget(linkCtx, late) {
...
    if (linkCtx.elem.nodeName === "SELECT" && linkCtxType === "link" && !linkCtx.attr
        && linkCtx.convert !== undefined) {

linkCtx doesn't have the convert property and so it does not go into the if statement.

BorisMoore commented 3 years ago

Thanks for calling this out. On investigation I found that there are also some related issues on other slightly different scenarios involving data-linking on <select> elements. Here is a proposed update which should address those cases, as well as this bug.

jsviews8d.zip

Let me know if it works for you...

johan-ohrn commented 3 years ago

I'm happy to inform you that it works like a charm! Thanks

BorisMoore commented 3 years ago

Resolved in v1.0.8