mirror of
https://github.com/frappe/books.git
synced 2024-12-24 20:00:29 +00:00
docs: update docs to mention conditional fields
This commit is contained in:
parent
b515e2f732
commit
1b9aa921f9
@ -6,14 +6,20 @@ Note: A model is called `DocType` in Frappe.js
|
|||||||
|
|
||||||
### Fields
|
### 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
|
- `fieldname`: Column name in database / property name.
|
||||||
- `fieldtype`: Data type ([see details](fields.md))
|
- `fieldtype`: Data type ([see details](fields.md)).
|
||||||
- `label`: Display label
|
- `label`: Display label.
|
||||||
- `required`: Is mandatory
|
- `required`: Is mandatory.
|
||||||
- `hidden`: Is hidden
|
- `hidden`: Is hidden.
|
||||||
- `disabled`: Is disabled
|
- `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
|
### Example
|
||||||
|
|
||||||
@ -28,7 +34,7 @@ module.exports = {
|
|||||||
"fieldname": "subject",
|
"fieldname": "subject",
|
||||||
"label": "Subject",
|
"label": "Subject",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"reqd": 1
|
"required": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
@ -44,8 +50,14 @@ module.exports = {
|
|||||||
"Closed"
|
"Closed"
|
||||||
],
|
],
|
||||||
"default": "Open",
|
"default": "Open",
|
||||||
"reqd": 1
|
"required": 1
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "postingDate",
|
||||||
|
"label": "Posting Date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"required": (doc) => doc.status === "Closed"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user