2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/docs/client/controls.md

89 lines
1.4 KiB
Markdown
Raw Normal View History

2018-01-10 12:49:52 +00:00
# Controls
Frappe.js comes in with built-in controls for various types of inputs
## Creating
2018-02-08 12:28:51 +00:00
A new control can be created with `control.makeControl` method.
2018-01-10 12:49:52 +00:00
```js
const controls = require('./controls');
2018-02-08 12:28:51 +00:00
let control = controls.makeControl({
2018-01-10 12:49:52 +00:00
fieldname: 'test',
fieldtype: 'Data',
label: 'Test Control'
}, body);
```
## Structure
The control has the following structure of HTML Elements
2018-02-08 12:28:51 +00:00
- `formGroup`
2018-01-10 12:49:52 +00:00
- `label`
- `input`
- `description`
## Types
Type of control is defined by the `fieldtype` property.
### Data
Short text input (`<input>`)
## Text
Long text input (`<textarea>`)
## Select
2018-01-31 12:56:21 +00:00
Select a single value from a list of options (`<select>`)
Options can be set in the `options` property as a list
Example:
```js
2018-02-08 12:28:51 +00:00
let control = controls.makeControl({
2018-01-31 12:56:21 +00:00
fieldname: 'test',
fieldtype: 'Select',
label: 'Test Select',
options: [
"Option 1",
"Option 2"
]
}, body);
```
## Link
You can select a value from another DocType with a Link type field. The value of the target table should be in "target"
Example:
```js
2018-02-08 12:28:51 +00:00
let control = controls.makeControl({
2018-01-31 12:56:21 +00:00
fieldname: 'user',
fieldtype: 'Link',
label: 'User',
target: 'User'
}, body);
```
2018-02-08 12:28:51 +00:00
## Table
A table control renders a grid object (datatable). The columns of the table are defined by the `childtype` property of the field definition
Example:
```js
let control = controls.makeControl({
fieldname: 'roles',
fieldtype: 'Table',
label: 'Roles',
childtype: 'User Role'
}, body);
```