# j-ListForm

> j-ListForm: NEW: delay {Number} initial delay for displaying detail (default: 1000 ms); NEW: component.add() opens a form for creating record

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 643a9afb1e999c23004c60d0e861d476857792aabf44e854599de9b65ed9561a
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

__Configuration__:

- `autofocus {String/Boolean}` focuses the first input element, `string` means a custom selector (default: `false`)
- `empty {String}` empty list text (default: `---`)
- `default {Boolean}` performs `DEFAULT()` method for the form scope (default: `true`)
- `required {Boolean}` controll will be "required" (default: `false`)
- `enter {Boolean}` allows to use `enter` as submit (default: `false`)
- `disabled {Boolean}` disables the control (default: `false`)
- `formclass {String}` a custom class for form container
- `itemclass {String}` a custom class for item container
- `create {String}` a link to a function `function(empty_object, callback(DEFAULT_ITEM_OBJECT), arr)` (`null` value skips creating)
- `submit {String}` a link to a function `function(form_data, callback(NEW_DATA), arr, item_ref_in_items)` (`null` value skips updating)
- `update {String}` a link to a function `function(form_data, callback(NEW_DATA), arr, item_ref_in_items)` (`null` value skips updating)
- `remove {String}` a link to a function `function(remove_item, callback(really_remove?), arr)`
- `selector {String}` a jQuery selector for custom template (outside of the component). Works like `custom template` in [data-binding](https://wiki.totaljs.com/jcomponent/08-data-binding/)
- `footertop {Boolean}` moves the footer on the top of the component (default: `false`)
- `move {String}` a link to a function `function(items)`
- `newbie {String}` a property name for every new item (it will always contain `true` value)
- `plugin {String}` a custom plugin name inside the component (default: `component.ID`)
- `invalidform {Boolean}` disables `j-Validate` component if the `j-ListForm` is in editing mode (default: `false`)
- __NEW__: `delay {Number}` initial delay for displaying detail (default: `1000` ms)

The component needs to have defined 3 templates wrapped in `<script type="text/html">`:

- `1` first - with a Tangular template for rendering of item
- `2` second - a form with components (the form will be wrapped in isolated scope)
- `3` footer - a footer with button for `create` item

__Good to know:__

The component watches a click event on all buttons with `name` attribute:

- `name="submit"` performs submit/save of data to the model
- `name="update"` performs submit/save of data to the model
- `name="remove"` removes the current item from the model
- `name="cancel"` cancels editing
- `name="create"` creates an empty form
- `form` contains `ui-listform-new` class when creating a new item

__Listing buttons:__

- `name="remove"` removes item
- `name="up"` moves item to up
- `name="down"` moves item to down

__Methods:__

- __NEW__: `component.add()` opens a form for creating record

Use it with `<ui-component name="listform">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<style>
	.ui-listform-item { height: 26px; line-height: 26px; overflow: hidden; padding: 0 5px; }
	button { background-color: white; border-radius: 2px; border: 1px solid #E0E0E0; font-size: 12px; height: 28px; line-height: 27px; padding: 0 10px; }
	button i { margin-right: 5px; }
	button:disabled { color: gray; background-color: #F8F8F8; }
	.ui-dark button { background-color: #303030; border-color: #454545; }
	.ui-dark button:disabled { background-color: #252525; color: #404040; }
</style>

<div style="width:400px">

	<ui-component name="listform" path="users" config="autofocus:1">

		<!-- LIST RENDERING -->
		<script type="text/html">
			<div>
				<div class="pull-right">
					<button name="up"><i class="ti ti-arrow-up"></i></button>
					<button name="down"><i class="ti ti-arrow-down"></i></button>
					<button name="remove"><i class="ti ti-remove"></i></button>
				</div>
				{{ name }}
			</div>
		</script>

		<!-- FORM RENDERING -->
		<script type="text/html">
			<div class="padding">
				<ui-component name="input" path="?.name" config="required:1" default="''" class="m">Name</ui-component>
				<ui-component name="validate" path="?">
					<button name="submit"><i class="ti ti-save"></i>Save</button>
					<button name="remove">Remove</button>
					<button name="cancel">Cancel</button>
				</ui-component>
			</div>
		</script>

		<!-- FOOTER -->

		<script type="text/html">
			<div style="margin-top:10px"><button name="create"><i class="ti ti-plus-circle green"></i>Create new</button></div>
		</script>

	</ui-component>
	<hr />
	<ui-bind path="users" config="text:STRINGIFY(value)" style="font-family:monospace" class="block"></ui-bind>

</div>

<script>

	var users = [{ name: 'Total.js' }, { name: 'Flow' }, { name: 'jComponent' }];

</script>
```
