# j-Rules

> The component can create a simple rules which you can transform to some engines like Total.js Flow. The component uses j-Directory component.

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

The component can create a simple rules which you can transform to some engines like Total.js Flow. The component uses `j-Directory` component.


__Configuration__:

- `dirsearc {String}h` A placeholder for search input in `j-Directory`, default: `search`

__Data declaration__:

```js
var form = [];
form.push({ enabled: true, label: 'CPU', name: 'cpu', type: 'number', comparer: '==', value: 0, note: 'Value in mega bytes' });
form.push({ enabled: false, label: 'Memory', name: 'memory', type: 'number', comparer: '>', value: 0 });
form.push({ enabled: true, label: 'Error', name: 'error', type: 'string', comparer: '==', items: [{ name: 'Error', id: 'error' }, { name: 'Obsolete', id: 'obsolete' }] });
form.push({ enabled: false, label: 'Offline', name: 'offline', type: 'boolean', comparer: '==', value: 0 });
```

__Data properties in data declaration__:

- `name {String}` an item identifier (required)
- `label {String}` a label (required)
- `note {String}` a small note under control
- `type {String}` a type, lower-case (required)
- `items {Object Array}` items for `string` type only  in the form `[{ id: String, name: String }]`
- `enabled {Boolean}` enables item
- `comparer {String}` can be `==`, `!=`, `>`, `>=`, `<=`, `<` (required)
- `value {Number/Boolean/String}` a value

__Allowed types in data__:

- `string`
- `boolean`
- `number`

Use it with `<ui-component name="rules">`. 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
<ui-component name="LAZY directory"></ui-component>

<div style="width:600px;padding:20px">
	<ui-component name="rules" path="form"></ui-component>
</div>

<script>
	var form = [];
	form.push({ enabled: true, label: 'CPU', name: 'cpu', type: 'number', comparer: '==', placeholder: '', value: 0, note: 'Value in mega bytes' });
	form.push({ enabled: false, label: 'Memory', name: 'memory', type: 'number', comparer: '>', placeholder: '', value: 0 });
	form.push({ enabled: true, label: 'Error', name: 'error', type: 'string', comparer: '==', items: [{ name: 'Error', id: 'error' }, { name: 'Obsolete', id: 'obsolete' }] });
	form.push({ enabled: false, label: 'Offline', name: 'offline', type: 'boolean', comparer: '==', value: 0 });
</script>
```
