Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion forms_pro/forms_pro/doctype/form_field/form_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"engine": "InnoDB",
"field_order": [
"reqd",
"hidden",
"label",
"fieldtype",
"fieldname",
Expand Down Expand Up @@ -68,13 +69,19 @@
"fieldname": "conditional_logic",
"fieldtype": "Code",
"label": "Conditional Logic"
},
{
"default": "0",
"fieldname": "hidden",
"fieldtype": "Check",
"label": "Hidden"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2026-01-14 21:40:40.060805",
"modified": "2026-01-15 00:41:11.397823",
"modified_by": "Administrator",
"module": "Forms Pro",
"name": "Form Field",
Expand Down
1 change: 1 addition & 0 deletions forms_pro/forms_pro/doctype/form_field/form_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FormField(Document):
"Checkbox",
"Rating",
]
hidden: DF.Check
label: DF.Data
options: DF.SmallText | None
parent: DF.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ const fieldProperties = computed(() => {
description: "If enabled, the field becomes required and cannot be left blank.",
},
},
{
fieldname: "hidden",
component: FormControl,
props: {
type: "checkbox",
label: "Hidden",
description: "If enabled, the field is hidden from the form.",
},
},
{
fieldname: "description",
component: FormControl,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/formfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type FormField = {
fieldtype: FormFieldTypes;
description?: string;
reqd?: boolean;
hidden?: boolean;
options?: string;
default?: string;
idx?: number;
Expand Down
34 changes: 22 additions & 12 deletions frontend/src/utils/conditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,27 @@ function evaluateConditions(
}

/**
* Determine if a field should be visible based on conditional logic rules
* defined on other fields that target this field. Visibility is driven by
* rules on other fields, not a property on the field itself. A field is visible if:
* - No conditional logic rules target it, OR
* - At least one "Show Field" action evaluates to true, OR
* - No "Hide Field" actions evaluate to true
* Determine if a field should be visible based on:
* 1. The field's `hidden` property (base state)
* 2. Conditional logic rules defined on other fields that target this field
*
* Visibility logic:
* - If field.hidden === true, field starts as hidden
* - If field.hidden === false or undefined, field starts as visible
* - Conditional logic can override the base state:
* - "Show Field" action can make a hidden field visible
* - "Hide Field" action can make a visible field hidden
* - If no conditional logic applies, the base hidden state is used
*/
export function shouldFieldBeVisible(
field: FormField,
formValues: Record<string, any>,
allFields: FormField[]
): boolean {
// Start with the field's base hidden state
// If hidden is true, field is hidden by default; if false/undefined, it's visible
const baseIsVisible = !field.hidden;

// Find all conditional logic rules that target this field
const targetingRules: ConditionalLogic[] = [];

Expand All @@ -239,9 +248,9 @@ export function shouldFieldBeVisible(
}
});

// If no rules target this field, it's visible
// If no rules target this field, use the base hidden state
if (targetingRules.length === 0) {
return true;
return baseIsVisible;
}

// Check each rule
Expand All @@ -260,18 +269,19 @@ export function shouldFieldBeVisible(
}
}

// If any "Show Field" rule is met, field is visible
// Conditional logic overrides base state:
// - "Show Field" action can override hidden state (make it visible)
if (hasShowRule) {
return true;
}

// If any "Hide Field" rule is met, field is hidden
// - "Hide Field" action can override visible state (make it hidden)
if (hasHideRule) {
return false;
}

// Default: field is visible if no rules are met
return true;
// If no conditional rules are met, use the base hidden state
return baseIsVisible;
}

/**
Expand Down