2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 11:55:46 +00:00

docs: update docs to mention conditional fields

This commit is contained in:
18alantom 2021-11-05 17:46:12 +05:30
parent b515e2f732
commit 1b9aa921f9

View File

@ -6,14 +6,20 @@ Note: A model is called `DocType` in Frappe.js
### Fields
Every model must have a set of fields (these become database columns). All fields must have
Every model must have a set of fields (these become database columns). All fields may have the following properties:
- `fieldname`: Column name in database / property name
- `fieldtype`: Data type ([see details](fields.md))
- `label`: Display label
- `required`: Is mandatory
- `hidden`: Is hidden
- `disabled`: Is disabled
- `fieldname`: Column name in database / property name.
- `fieldtype`: Data type ([see details](fields.md)).
- `label`: Display label.
- `required`: Is mandatory.
- `hidden`: Is hidden.
- `disabled`: Is disabled.
### Conditional Fields
The following fields: `hidden`, `required` can be conditional, depending on the values of other fields.
This is done by setting it's value to a function that receives an object with all the models fields and their values and returns a boolean.
See _"Posting Date"_ in the example below.
### Example
@ -28,7 +34,7 @@ module.exports = {
"fieldname": "subject",
"label": "Subject",
"fieldtype": "Data",
"reqd": 1
"required": 1
},
{
"fieldname": "description",
@ -44,8 +50,14 @@ module.exports = {
"Closed"
],
"default": "Open",
"reqd": 1
}
"required": 1
},
{
"fieldname": "postingDate",
"label": "Posting Date",
"fieldtype": "Date",
"required": (doc) => doc.status === "Closed"
},
]
}
```