2
0
mirror of https://github.com/frappe/books.git synced 2024-12-27 04:32:41 +00:00
books/docs/client/controls.md
2018-02-08 17:58:51 +05:30

1.4 KiB

Controls

Frappe.js comes in with built-in controls for various types of inputs

Creating

A new control can be created with control.makeControl method.

const controls = require('./controls');

let control = controls.makeControl({
	fieldname: 'test',
	fieldtype: 'Data',
	label: 'Test Control'
}, body);

Structure

The control has the following structure of HTML Elements

  • formGroup
    • label
    • input
    • description

Types

Type of control is defined by the fieldtype property.

Data

Short text input (<input>)

Text

Long text input (<textarea>)

Select

Select a single value from a list of options (<select>)

Options can be set in the options property as a list

Example:

let control = controls.makeControl({
	fieldname: 'test',
	fieldtype: 'Select',
	label: 'Test Select',
	options: [
		"Option 1",
		"Option 2"
	]
}, body);

You can select a value from another DocType with a Link type field. The value of the target table should be in "target"

Example:

let control = controls.makeControl({
	fieldname: 'user',
	fieldtype: 'Link',
	label: 'User',
	target: 'User'
}, body);

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:

let control = controls.makeControl({
	fieldname: 'roles',
	fieldtype: 'Table',
	label: 'Roles',
	childtype: 'User Role'
}, body);