# j-ListMenuEditable

> Component for editable list menu

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

Component for editable list menu

- You can change CSS for your needs.


__Configuration__:

- `iconremove {String}` optional, change `remove` button icon. It's fontawesome icon without `ti-` part (default: `times`)
- `defaulticon {String}` optional, change `edit` button icon (default: `pencil-alt`)
- `addicon {String}` optional, will change `add` button icon (default: `plus-square`)
- `placeholder {String}` optional, a placeholder for input (default: `Write text and press ENTER`)
- `class {String}` CSS class for selected item (default: `selected`)
- `title {String}` optional, will add title on top of list menu (important if you want use `addicon` and `addclick`)
- `key {String}` optional, a default `key` for `text` value (default: `name`)
- `click {String}` optional, action after click on item in menu. Path to function(element, index)
- `addclick {String}` optional, action after click on `add `button. Path to function() executes when user click on `add` icon
- `editclick {String}` optional, action after click on `edit` button. Path to function(element, index)

__Methods__:

- `component.add(object)` - This function will push object into path (can be null)
- `component.edit(index)` - Function will enable edit on element
- `component.remove(index)` - Function will remove the index

__Good to know__:

Path __must be__ array of objects. After click on item in menu
Supports dynamic evaluation of the content of `<script type="text/html">`. The example below contains a script with HTML and the component evaluates the content when the component is creating (only once).

```
<ui-component name="listmenueditable" path="tags">
	<script type="text/html">
		{{ if mycolor }}
			<i class="ti ti-circle" style="color: {{ mycolor }}"></i>
		{{ fi }}
		{{ name }}
	</script>
</ui-component>
```

__Adding of custom class__:

```javascript
var opt = {};
opt.items = [];
opt.push({ name: 'Total.js', classname: 'your_class_name' });
```

__Toggle editable__:

```javascript
var opt = {};
opt.items = [];
opt.push({ name: 'Total.js', editable: true });
```

Use it with `<ui-component name="listmenueditable">`. 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: Denis Granec. Source: the Componentator components repository, MIT license.

```html example.html
<!-- EXAMPLE DEPENDENCIES -->
<ui-component name="menu"></ui-component>

<div style="width: 400px;">
	<ui-component name="listmenueditable" path="tags" config="title:All tags;editclick:edit;addclick:add;click:click">
		<script type="text/html">
			{{ if mycolor }}
				<i class="ti ti-circle-alt" style="color: {{ mycolor }}"></i>
			{{ fi }}
			{{ name }}
		</script>
	</ui-component>
</div>

<script>
	var tags = [{ name: 'Tag 1', mycolor: '#00B9D7', editable: true, classname: 'customclass', mycustomdata: 'ola' }, { name: 'Tag 2', mycolor: '#00A06E', editable: true, mycustomdata: 'ola2' }];

	function click(el, item, index) {
		console.log('clicked index', index, 'item', item);
	}

	function edit(el, index, icon) {
		var opt = {};
		opt.items = [{ name: 'Edit', id: 'edit' }, { name: 'Remove', icon: 'trash', id: 'remove' }];
		opt.align = 'center';
		opt.element = icon;
		opt.callback = function(selected) {
			switch (selected.id) {
				case 'edit':
					SETTER('listmenueditable/edit', index);
					break;
				case 'remove':
					SETTER('listmenueditable/remove', index);
					break;
			}
		};
		SETTER('menu/show', opt);
	}

	function add() {
		SETTER('listmenueditable/add', { name: 'New tag', mycolor: '#8e44ad', editable: true });
	}
</script>
```
