ForgejComponent
en

jComponent

More ui-bind commands: attributes, values, state and formatting

jComponent 20 · jcomponent@20 jcomponentfrontendbinding Executed with jComponent 20

Besides text, show and hide, ui-bind has commands for the common DOM changes. Each command is name:expression (or name selector:expression to apply it to an inner element), and value is the value of the path:

CommandDoes
html:exprsets the inner HTML (escape it yourself!)
title:expr, href:expr, src:exprsets that attribute
attr name:exprsets any attribute
value:exprsets the value of a form control
disabled:expr / enabled:exprdisables or enables the controls inside
checked:exprchecks the checkbox inside
.class:expradds or removes the class

Options of the whole element: format:yyyy-MM-dd formats a date value before it is printed (for numbers call format() in the expression: text:value.format(2)), empty:none is shown when the value is empty, changes skips updates when the value did not change, and delay:200 waits that many milliseconds before rendering.

public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<ui-bind path="user" config="attr data-id:value.id;title:value.name;text:value.name" class="greeting"></ui-bind>
	<ui-bind path="product.price" config="text:value.format(2)" class="price"></ui-bind>
	<ui-bind path="product.date" config="text:value;format:yyyy-MM-dd" class="date"></ui-bind>
	<ui-bind path="user.admin" config="disabled:!value"><button type="button" id="delete">Delete</button></ui-bind>
	<ui-bind path="user.nick" config="value input:value;empty:anonymous"><input type="text" /></ui-bind>
	<ui-bind path="user.nick" config="text:value;empty:anonymous" class="nick"></ui-bind>

	<script>
		SET('user', { id: 7, name: 'Peter', admin: false, nick: '' });
		SET('product', { price: 1234.5, date: new Date(2026, 9, 16) });
	</script>

</body>
</html>
Try it in your browser

Edit the example and run it. It runs in an isolated frame in your browser; nothing is sent to our server.

Preview