Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a tmpl selector that begins with a # but is not an ID selector does not work #455

Closed
nfplee opened this issue Jan 13, 2023 · 5 comments

Comments

@nfplee
Copy link

nfplee commented Jan 13, 2023

Please see the following JSFiddle:

https://jsfiddle.net/p5urz4ey/

This works fine if you change the version to 1.0.10.

@BorisMoore
Copy link
Owner

Thanks for calling this out, Lee. I have a fix, which I will share with you in the coming days...

@BorisMoore
Copy link
Owner

You can test my proposed fix, using this updated version of jsviews.js:

jsviews1013.js.txt

It has line 1125:
} if (!elem && $.fn && !$sub.rTmpl.test(value)) {
which replaces the previous version:
} else if ($.fn && !$sub.rTmpl.test(value)) {

Let me know if this works for you.
Thanks

@nfplee
Copy link
Author

nfplee commented Jan 23, 2023

Thanks yeah that seems to do the trick.

@BorisMoore BorisMoore changed the title Using a # in a tmpl selector doesn't work Using a tmpl selector that begins with a # but is not an ID selector does not work Mar 31, 2023
@BorisMoore
Copy link
Owner

To explain this issue:

The JSFiddle linked above includes the line:
<tbody data-link="{for people tmpl='#people .item-template'}"></tbody>

It loads the template under the script element with class "item-template", which is itself a descendant of the element (in fact a <div>) which has ID "people".

The selector '#people .item-template' - a "descendant selector" starts with a '#', and the previous JsRender code assumed that a selector starting with a '#' is an "ID selector". However the presence of white space in the selector means that it is not a valid "ID selector" and is in fact a "descendant selector". The bug fix ensures that JsRender no longer assumes that a selector starting with "#" is an "ID selector", and instead interprets the selector correctly, and so loads the correct template in the JSFiddle example.

The issue is with JsRender as well as with JsViews (which uses JsRender)

BorisMoore added a commit to BorisMoore/jsrender that referenced this issue Mar 31, 2023
This update contains a minor bug fix:
BorisMoore/jsviews#455: "Using a tmpl selector
that begins with a # but is not an ID selector does not work".

This change applies to jsrender and jsviews

The update also includes some minor documentation updates, and moves
to the latest versions of JQuery and JQuery UI, for all samples, examples,
and test pages.

Sync with other changes in v1.0.13 for JsViews
BorisMoore added a commit that referenced this issue Apr 1, 2023
This update contains a minor bug fix:
#455: "Using a tmpl selector
that begins with a # but is not an ID selector does not work".

This change applies to jsrender and jsviews

The update also includes some minor documentation updates, and moves
to the latest versions of JQuery and JQuery UI, for all samples, examples,
and test pages.

Sync with other changes in v1.0.13 for JsViews
@BorisMoore
Copy link
Owner

Resolved in release v1.0.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants