优化form_builder
This commit is contained in:
parent
1c5b551206
commit
609670e37d
@ -23,6 +23,10 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: ""
|
default: ""
|
||||||
},
|
},
|
||||||
|
pagetypeRecord: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
readOnly: {
|
readOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
@ -86,6 +90,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
store.initialize(props.fields, {
|
store.initialize(props.fields, {
|
||||||
pagetype: props.pagetype,
|
pagetype: props.pagetype,
|
||||||
|
pg: props.pagetypeRecord,
|
||||||
readOnly: props.readOnly,
|
readOnly: props.readOnly,
|
||||||
isCustomizeForm: props.isCustomizeForm,
|
isCustomizeForm: props.isCustomizeForm,
|
||||||
});
|
});
|
||||||
@ -97,6 +102,7 @@ watch(
|
|||||||
(newFields) => {
|
(newFields) => {
|
||||||
store.initialize(newFields, {
|
store.initialize(newFields, {
|
||||||
pagetype: props.pagetype,
|
pagetype: props.pagetype,
|
||||||
|
pg: props.pagetypeRecord,
|
||||||
readOnly: props.readOnly,
|
readOnly: props.readOnly,
|
||||||
isCustomizeForm: props.isCustomizeForm,
|
isCustomizeForm: props.isCustomizeForm,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -17,7 +17,7 @@ let pagefieldDf = computed(() => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
df.depends_on &&
|
df.depends_on &&
|
||||||
!evaluateDependsOnValue(df.depends_on, store.form.selected_field)
|
!evaluateDependsOnValue(df.depends_on, store.form.selected_field, store.pg)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,7 +116,7 @@ export const DEFAULT_PAGEFIELD_PROPERTIES = [
|
|||||||
// Visibility Section
|
// Visibility Section
|
||||||
{ fieldname: "visibility_section", fieldtype: "Section Break", label: t("Visibility") },
|
{ fieldname: "visibility_section", fieldtype: "Section Break", label: t("Visibility") },
|
||||||
{ fieldname: "hidden", label: t("Hidden"), fieldtype: "Check" },
|
{ fieldname: "hidden", label: t("Hidden"), fieldtype: "Check" },
|
||||||
{ fieldname: "show_on_timeline", label: t("Show on Timeline"), fieldtype: "Check", depends_on: "eval:doc.hidden" },
|
{ fieldname: "show_on_timeline", label: t("Show on Timeline"), fieldtype: "Check", depends_on: "eval:pg.hidden" },
|
||||||
{ fieldname: "bold", label: t("Bold"), fieldtype: "Check" },
|
{ fieldname: "bold", label: t("Bold"), fieldtype: "Check" },
|
||||||
{ fieldname: "allow_in_quick_entry", label: t("Allow in Quick Entry"), fieldtype: "Check" },
|
{ fieldname: "allow_in_quick_entry", label: t("Allow in Quick Entry"), fieldtype: "Check" },
|
||||||
{ fieldname: "translatable", label: t("Translatable"), fieldtype: "Check", depends_on: "eval:['Data', 'Select', 'Text', 'Small Text', 'Text Editor'].includes(pg.fieldtype)" },
|
{ fieldname: "translatable", label: t("Translatable"), fieldtype: "Check", depends_on: "eval:['Data', 'Select', 'Text', 'Small Text', 'Text Editor'].includes(pg.fieldtype)" },
|
||||||
@ -126,7 +126,7 @@ export const DEFAULT_PAGEFIELD_PROPERTIES = [
|
|||||||
{ fieldname: "column_break_28", fieldtype: "Column Break" },
|
{ fieldname: "column_break_28", fieldtype: "Column Break" },
|
||||||
{ fieldname: "depends_on", label: t("Display Depends On (JS)"), fieldtype: "Code", options: "JS" },
|
{ fieldname: "depends_on", label: t("Display Depends On (JS)"), fieldtype: "Code", options: "JS" },
|
||||||
{ fieldname: "collapsible", label: t("Collapsible"), fieldtype: "Check", depends_on: "eval:pg.fieldtype=='Section Break'" },
|
{ fieldname: "collapsible", label: t("Collapsible"), fieldtype: "Check", depends_on: "eval:pg.fieldtype=='Section Break'" },
|
||||||
{ fieldname: "collapsible_depends_on", label: t("Collapsible Depends On (JS)"), fieldtype: "Code", options: "JS", depends_on: "eval:doc.collapsible" },
|
{ fieldname: "collapsible_depends_on", label: t("Collapsible Depends On (JS)"), fieldtype: "Code", options: "JS", depends_on: "eval:pg.collapsible" },
|
||||||
{ fieldname: "hide_border", label: t("Hide Border"), fieldtype: "Check", depends_on: "eval:pg.fieldtype=='Section Break'" },
|
{ fieldname: "hide_border", label: t("Hide Border"), fieldtype: "Check", depends_on: "eval:pg.fieldtype=='Section Break'" },
|
||||||
|
|
||||||
// List / Search Settings Section
|
// List / Search Settings Section
|
||||||
@ -141,7 +141,7 @@ export const DEFAULT_PAGEFIELD_PROPERTIES = [
|
|||||||
// Permissions Section
|
// Permissions Section
|
||||||
{ fieldname: "permissions", fieldtype: "Section Break", label: t("Permissions") },
|
{ fieldname: "permissions", fieldtype: "Section Break", label: t("Permissions") },
|
||||||
{ fieldname: "read_only", label: t("Read Only"), fieldtype: "Check" },
|
{ fieldname: "read_only", label: t("Read Only"), fieldtype: "Check" },
|
||||||
{ fieldname: "allow_on_submit", label: t("Allow on Submit"), fieldtype: "Check" },
|
{ fieldname: "allow_on_submit", label: t("Allow on Submit"), fieldtype: "Check", depends_on: "eval:parent.is_submittable" },
|
||||||
{ fieldname: "ignore_user_permissions", label: t("Ignore User Permissions"), fieldtype: "Check" },
|
{ fieldname: "ignore_user_permissions", label: t("Ignore User Permissions"), fieldtype: "Check" },
|
||||||
{ fieldname: "allow_bulk_edit", label: t("Allow Bulk Edit"), fieldtype: "Check", depends_on: "eval:pg.fieldtype=='Table'" },
|
{ fieldname: "allow_bulk_edit", label: t("Allow Bulk Edit"), fieldtype: "Check", depends_on: "eval:pg.fieldtype=='Table'" },
|
||||||
{ fieldname: "make_attachment_public", label: t("Make Attachment Public (by default)"), fieldtype: "Check", depends_on: "eval:['Attach', 'Attach Image'].includes(pg.fieldtype)" },
|
{ fieldname: "make_attachment_public", label: t("Make Attachment Public (by default)"), fieldtype: "Check", depends_on: "eval:['Attach', 'Attach Image'].includes(pg.fieldtype)" },
|
||||||
|
|||||||
@ -147,8 +147,11 @@ export function getTableColumns(df, childPagetype) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate depends_on expression
|
* Evaluate depends_on expression
|
||||||
|
* @param {string|boolean|function} expression - The depends_on expression
|
||||||
|
* @param {object} pg - The current field/document being evaluated (usually selected_field)
|
||||||
|
* @param {object} parent - Optional parent document (usually the PageType record)
|
||||||
*/
|
*/
|
||||||
export function evaluateDependsOnValue(expression, pg) {
|
export function evaluateDependsOnValue(expression, pg, parent = null) {
|
||||||
if (!pg) return false;
|
if (!pg) return false;
|
||||||
|
|
||||||
let out = null;
|
let out = null;
|
||||||
@ -159,13 +162,13 @@ export function evaluateDependsOnValue(expression, pg) {
|
|||||||
out = expression(pg);
|
out = expression(pg);
|
||||||
} else if (expression.substr(0, 5) === "eval:") {
|
} else if (expression.substr(0, 5) === "eval:") {
|
||||||
try {
|
try {
|
||||||
const doc = pg;
|
|
||||||
// Define in_list function for eval context
|
// Define in_list function for eval context
|
||||||
const in_list = (list, value) => list && list.includes(value);
|
const in_list = (list, value) => list && list.includes(value);
|
||||||
// Simple evaluation for common patterns
|
// Simple evaluation for common patterns
|
||||||
out = eval(expression.substr(5));
|
out = eval(expression.substr(5));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Invalid "depends_on" expression:', expression);
|
// If evaluation fails (e.g., parent is null), return false
|
||||||
|
// This is expected for conditions like "parent.is_submittable" when parent is not yet loaded
|
||||||
out = false;
|
out = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -65,6 +65,7 @@ function handleDirtyChange(isDirty: boolean) {
|
|||||||
<FormBuilderComponent
|
<FormBuilderComponent
|
||||||
:fields="fields"
|
:fields="fields"
|
||||||
:pagetype="pagetypeName"
|
:pagetype="pagetypeName"
|
||||||
|
:pagetype-record="record"
|
||||||
:readOnly="!canEdit"
|
:readOnly="!canEdit"
|
||||||
:isCustomizeForm="false"
|
:isCustomizeForm="false"
|
||||||
@update:fields="handleFieldsUpdate"
|
@update:fields="handleFieldsUpdate"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user