1 set_df_property Options
A comprehensive reference guide to dynamically modifying DocField properties at runtime โ because hardcoding forms is so last season.
Table of Contents
- ๐ Overview
- ๐ Visibility & Display Properties
- ๐ List View & Filter Properties
- ๐ Field Type & Options
- ๐ Validation & Mandatory Properties
- ๐ Child Table Properties
- ๐ Data & Formatting Properties
- ๐ Permission & Security Properties
- ๐ป Advanced Properties
- ๐ Practical Usage Examples
- ๐ก Important Notes
- ๐ฆ Related Methods
๐ Overview
set_df_property is a powerful method in Frappe's client-side JavaScript API that allows you to dynamically modify DocField properties at runtime. Below is the complete reference of all available property options organized by category.
๐ Visibility & Display Properties
These properties control whether and how fields appear in the form.
| Property | Type | Purpose | Example |
|---|---|---|---|
hidden |
Boolean (0/1) | Hide or show a field | frm.set_df_property('field_name', 'hidden', 1) |
depends_on |
String (JS code) | Show field conditionally based on evaluation | frm.set_df_property('field', 'depends_on', 'eval:doc.other_field=="value"') |
read_only |
Boolean (0/1) | Make field non-editable | frm.set_df_property('field', 'read_only', 1) |
read_only_depends_on |
String (JS code) | Make field read-only conditionally | frm.set_df_property('field', 'read_only_depends_on', 'eval:doc.submitted==1') |
collapsible |
Boolean (0/1) | Make Section Break collapsible | frm.set_df_property('section', 'collapsible', 1) |
collapsible_depends_on |
String (JS code) | Collapsibility based on condition | frm.set_df_property('section', 'collapsible_depends_on', 'eval:doc.status!="Closed"') |
bold |
Boolean (0/1) | Display field label in bold text | frm.set_df_property('field', 'bold', 1) |
print_hide |
Boolean (0/1) | Hide field from printed documents | frm.set_df_property('field', 'print_hide', 1) |
print_hide_if_no_value |
Boolean (0/1) | Hide from print only if field is empty | frm.set_df_property('field', 'print_hide_if_no_value', 1) |
report_hide |
Boolean (0/1) | Hide field from reports | frm.set_df_property('field', 'report_hide', 1) |
๐ List View & Filter Properties
These properties determine field visibility and filtering in list views.
| Property | Type | Purpose |
|---|---|---|
in_list_view |
Boolean (0/1) | Show field in list view columns |
in_filter |
Boolean (0/1) | Allow filtering by this field |
in_standard_filter |
Boolean (0/1) | Show in standard filter dropdown |
in_global_search |
Boolean (0/1) | Include in global search results |
in_preview |
Boolean (0/1) | Show in preview mode |
remember_last_selected_value |
Boolean (0/1) | Remember user's last filter selection |
๐ Field Type & Options
These properties change the field's datatype and available values.
| Property | Type | Purpose | Example |
|---|---|---|---|
fieldtype |
String | Change field's data type | frm.set_df_property('field', 'fieldtype', 'Text') |
options |
Array or String | Set available options for Select/Link fields | frm.set_df_property('status', 'options', ['Open', 'Closed']) |
Supported fieldtypes include: Data, Text, Text Editor, Select, Link, Dynamic Link, Currency, Float, Int, Date, Datetime, Checkbox, Table, and 20+ others.[docs.frappe]
๐ Validation & Mandatory Properties
These control field validation and whether fields are required.
| Property | Type | Purpose | Example |
|---|---|---|---|
reqd |
Boolean (0/1) | Make field mandatory | frm.set_df_property('title', 'reqd', 1) |
mandatory_depends_on |
String (JS code) | Make mandatory conditionally | frm.set_df_property('field', 'mandatory_depends_on', 'eval:doc.status=="Open"') |
unique |
Boolean (0/1) | Enforce unique values for this field | frm.set_df_property('email', 'unique', 1) |
set_only_once |
Boolean (0/1) | Field can only be set once, then becomes read-only | frm.set_df_property('field', 'set_only_once', 1) |
no_copy |
Boolean (0/1) | Don't copy this field when amending documents | frm.set_df_property('notes', 'no_copy', 1) |
allow_on_submit |
Boolean (0/1) | Allow editing after document is submitted | frm.set_df_property('notes', 'allow_on_submit', 1) |
๐ Child Table Properties
These properties are specific to Table fields.
| Property | Type | Purpose | Example |
|---|---|---|---|
cannot_add_rows |
Boolean (0/1) | Prevent users from adding new rows | frm.set_df_property('items', 'cannot_add_rows', true) |
cannot_delete_rows |
Boolean (0/1) | Prevent users from deleting rows | frm.set_df_property('items', 'cannot_delete_rows', true) |
allow_bulk_edit |
Boolean (0/1) | Allow bulk editing of table rows | frm.set_df_property('items', 'allow_bulk_edit', 1) |
๐ Data & Formatting Properties
These properties affect how field values are stored and displayed.
| Property | Type | Purpose | Example |
|---|---|---|---|
default |
String/Number | Set default field value | frm.set_df_property('field', 'default', 'default_value') |
precision |
Number | Decimal places for numeric fields | frm.set_df_property('amount', 'precision', 2) |
non_negative |
Boolean (0/1) | Field value must be >= 0 | frm.set_df_property('quantity', 'non_negative', 1) |
fetch_from |
String | Auto-fetch value from linked field | frm.set_df_property('field', 'fetch_from', 'other_field.value') |
fetch_if_empty |
Boolean (0/1) | Only fetch value if field is currently empty | frm.set_df_property('field', 'fetch_if_empty', 1) |
translatable |
Boolean (0/1) | Mark field as translatable to other languages | frm.set_df_property('description', 'translatable', 1) |
label |
String | Display label/field name | frm.set_df_property('field', 'label', 'New Label') |
description |
String | Help text shown below the field | frm.set_df_property('field', 'description', 'Help message') |
columns |
Number | Column width for table fields | frm.set_df_property('field', 'columns', 3) |
๐ Permission & Security Properties
These properties control field-level access and data safety.
| Property | Type | Purpose | Example |
|---|---|---|---|
permlevel |
Number | Permission level (0-9) for role-based access | frm.set_df_property('salary', 'permlevel', 2) |
ignore_user_permissions |
Boolean (0/1) | Bypass user permissions for this field | frm.set_df_property('field', 'ignore_user_permissions', 1) |
ignore_xss_filter |
Boolean (0/1) | Skip XSS sanitization (use with caution) | frm.set_df_property('html_field', 'ignore_xss_filter', 1) |
๐ป Advanced Properties
These are less commonly used but provide specialized functionality.
| Property | Type | Purpose |
|---|---|---|
link_filters |
JSON | Filters for Link field dropdown ({"field": "value"}) |
allow_in_quick_entry |
Boolean (0/1) | Show in quick entry dialog |
hide_border |
Boolean (0/1) | Hide Section Break border |
is_virtual |
Boolean (0/1) | Mark as virtual/computed field (read-only from DB) |
sort_options |
Boolean (0/1) | Allow sorting select field options |
๐ Practical Usage Examples
Scenario 1: Hide a field based on another field's value
frappe.ui.form.on('Sales Order', {
customer_type(frm) {
let show_gst = frm.doc.customer_type === 'Business';
frm.set_df_property('gst_number', 'hidden', show_gst ? 0 : 1);
}
});
Scenario 2: Disable child table row operations
frappe.ui.form.on('Purchase Order', {
refresh(frm) {
if (frm.doc.docstatus === 1) { // Document is submitted
frm.set_df_property('items', 'cannot_add_rows', true);
frm.set_df_property('items', 'cannot_delete_rows', true);
}
}
});
Scenario 3: Make field mandatory conditionally
frappe.ui.form.on('Leave Application', {
leave_type(frm) {
let is_half_day = frm.doc.leave_type === 'Half Day';
frm.set_df_property('half_day_type', 'reqd', is_half_day ? 1 : 0);
frm.set_df_property('half_day_type', 'hidden', is_half_day ? 0 : 1);
}
});
Scenario 4: Dynamic Select field options
frappe.ui.form.on('Lead', {
country(frm) {
let options = frm.doc.country === 'India'
? ['Delhi', 'Mumbai', 'Bangalore']
: ['New York', 'Los Angeles'];
frm.set_df_property('city', 'options', options);
frm.refresh_field('city');
}
});
๐ก Important Notes
- Always refresh the field after using
set_df_propertyfor visual changes to take effect:frm.refresh_field('fieldname') - Use
eval:prefix for conditional properties:'eval:doc.field=="value"' - Child table properties can be set the same way as regular fields
- For child table row properties, you may need to iterate through rows:
frm.fields_dict.items.grid.df.cannot_add_rows = true - Performance tip: Set properties in
setuporonloadevents rather than repeatedly inrefresh
๐ฆ Related Methods
frm.toggle_reqd(fieldname, boolean)โ Toggle mandatory status more efficientlyfrm.toggle_display(fieldname, boolean)โ Toggle visibilityfrm.toggle_enable(fieldname, boolean)โ Toggle read-only statusfrm.refresh_field(fieldname)โ Refresh field UI after changes
This comprehensive set of properties makes set_df_property an essential tool for creating dynamic, responsive forms in Frappe applications.frappe+3