Skip to content

add possibility to use templates based on https://github.com/BorisMoore/jsrender#1477

Merged
reiern70 merged 1 commit into
wicketstuff:masterfrom
reiern70:reiern70/use-js-render
Jun 11, 2026
Merged

add possibility to use templates based on https://github.com/BorisMoore/jsrender#1477
reiern70 merged 1 commit into
wicketstuff:masterfrom
reiern70:reiern70/use-js-render

Conversation

@reiern70

@reiern70 reiern70 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

add possibility to use templates based on https://github.com/BorisMoore/jsrender

Note: https://github.com/BorisMoore/jquery-tmpl is no longer maintained and https://github.com/BorisMoore/jsrender is the replacement for it. jquery-tmpl needs to be adapted to jQuery 4 but that will not happen. Support for jQuery 4 for jsrender might be added soon

BorisMoore/jsrender#377

@solomax solomax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, do we need any tests/demo for this functionality?

// warning, the template text should be of the form <a>...</a> in order to work
String render = "jQuery('%s').data('ui-autocomplete')._renderItem = function( ul, item ) { " // lf
+ "var content = jQuery.tmpl(jQuery('#%s').html(), item);" // lf
+ "var content = " + templateBehavior.getTemplateRenderingCode() // lf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be protected against NPEs ?
Both templateBehavior and templateBehavior.getTemplateRenderingCode() may return null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templateBehavior is not null.

protected String $()
			{
				if (templateBehavior != null)
				{
					// warning, the template text should be of the form <a>...</a> in order to work
					String render = "jQuery('%s').data('ui-autocomplete')._renderItem = function( ul, item ) { " // lf
							+ "var content = " + templateBehavior.getTemplateRenderingCode() // lf
							+ "return jQuery('<li/>').data('ui-autocomplete-item', item).append(content).appendTo(ul);" // lf
							+ "}";
					
					return super.$() + String.format(render, this.selector, templateBehavior.getToken());
				}

				return super.$();
			}

adding check for getTemplateRenderingCode

@reiern70

reiern70 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

LGTM, do we need any tests/demo for this functionality?

I will check. It seems to work Ok in our application in combination with custom values for autocomplete component.

@reiern70

Copy link
Copy Markdown
Contributor Author

LGTM, do we need any tests/demo for this functionality?

Added example

@reiern70 reiern70 merged commit 6c06b66 into wicketstuff:master Jun 11, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants