---
title: Getting started
project: jComponent V20
version: 20.015
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-015/guides/getting-started/
updated: 2026-11-18T18:15:21.747Z
---

# Getting started

> Build a working page with bound data and a custom component, starting from an empty file.

This guide takes you from an empty file to a working page with a custom input component and data bound to it. You need a text editor and a browser.

## Create the page

Create a file named `index.html` and load the library from the CDN:

```html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<title>My first page</title>
	<link rel="stylesheet" href="https://cdn.componentator.com/spa.min@20.css" />
	<script src="https://cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>

</body>
</html>
```

All the following code goes inside `<body>`. Open the file directly in the browser to see the result.

## Show a value

Write a value to the model with `SET()` and display it with a `<ui-bind>` element:

```html
<h1>Hello <ui-bind path="app.name" config="text"></ui-bind></h1>

<script>
	SET('app.name', 'Ana');
</script>
```

The page shows `Hello Ana`.

- `SET('app.name', 'Ana')` creates the global object `app` and stores the value in `app.name`.
- `path` tells `<ui-bind>` which value to listen to.
- `config="text"` tells it to render the value as text.

Every later `SET('app.name', ...)` updates the heading. Read more in [Paths](../paths/) and [Data binding](../data-binding/).

## Create a component

A component is a reusable widget. Declare it once with `COMPONENT()` and place it on the page with `<ui-component>`. Replace the content of `<body>` with this code:

```html
<h1>Hello <ui-bind path="app.name" config="text;empty:stranger"></ui-bind></h1>

<ui-component name="textbox" path="app.name" config="label:Your name;required:true"></ui-component>

<script>
COMPONENT('textbox', 'label:Name', function(self, config, cls) {

	self.make = function() {
		self.aclass(cls);
		self.html('<label></label><input type="text" />');
		self.autobind20();
	};

	self.configure = function(key, value) {
		if (key === 'label')
			self.find('label').text(value);
	};

	self.validate = function(value) {
		return !config.required || !!value;
	};

}, null, '.CLASS label { display: block; font-weight: bold; } .CLASS.ui-invalid input { border-color: red; }');

SET('app.name', 'Ana');
</script>
```

Type into the field and the heading follows your text. Clear the field and the heading shows `Hello stranger`, because `empty:stranger` in the `<ui-bind>` configuration sets the text for an empty value.

Here is what each part of the declaration does:

| Code | Purpose |
| --- | --- |
| `'textbox'` | The name used in `<ui-component name="textbox">` |
| `'label:Name'` | The default configuration, which the `config` attribute can override |
| `self.make` | Runs once for each instance and creates its HTML |
| `self.aclass(cls)` | Adds the CSS class `ui-textbox` to the element |
| `self.autobind20()` | Writes the content of the input to the model while the user types |
| `self.configure` | Runs for each configuration key |
| `self.validate` | Says if the current value is valid. The library then adds or removes the class `ui-invalid` |
| The last argument | CSS of the component, where `CLASS` stands for `ui-textbox` |

The component does not define how to show the value in the input. When a component has no `setter` of its own, the library writes the value into the first `input`, `select` or `textarea` inside the component.

## Run code from a button

Elements with the class `exec` call the function named in their `data-exec` attribute when they are clicked. Add a button that clears the model:

```html
<h1>Hello <ui-bind path="app.name" config="text;empty:stranger"></ui-bind></h1>

<ui-component name="textbox" path="app.name" config="label:Your name;required:true"></ui-component>

<button class="exec" data-exec="FUNC.clear">Clear</button>
```

Then add the function to the script, above the `SET()` call:

```js
FUNC.clear = function() {
	SET('app.name', '');
};
```

`FUNC` is an empty global object meant for your own functions. The click changes only the model. The input, the heading and the validation state all follow.

## The complete page

```html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<title>My first page</title>
	<link rel="stylesheet" href="https://cdn.componentator.com/spa.min@20.css" />
	<script src="https://cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>

	<h1>Hello <ui-bind path="app.name" config="text;empty:stranger"></ui-bind></h1>

	<ui-component name="textbox" path="app.name" config="label:Your name;required:true"></ui-component>

	<button class="exec" data-exec="FUNC.clear">Clear</button>

	<script>
		COMPONENT('textbox', 'label:Name', function(self, config, cls) {

			self.make = function() {
				self.aclass(cls);
				self.html('<label></label><input type="text" />');
				self.autobind20();
			};

			self.configure = function(key, value) {
				if (key === 'label')
					self.find('label').text(value);
			};

			self.validate = function(value) {
				return !config.required || !!value;
			};

		}, null, '.CLASS label { display: block; font-weight: bold; } .CLASS.ui-invalid input { border-color: red; }');

		FUNC.clear = function() {
			SET('app.name', '');
		};

		SET('app.name', 'Ana');
	</script>

</body>
</html>
```

## If something does not work

- **The component stays empty.** Check that the `name` attribute matches the name in `COMPONENT()`. For an unknown name, the library tries to download the component from the CDN and writes `jComponent: Downloading "name" component.` to the console.
- **The value does not change on the page.** Change the model with `SET()`. A direct assignment such as `app.name = 'Ana'` does not notify anybody until you call `UPD('app.name')`.

## Next steps

- [Paths](../paths/) explains how to address and change data.
- [Data binding](../data-binding/) shows everything `<ui-bind>` can do.
- [Creating components](../creating-components/) covers the whole component API.
