WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f32a906

Browse files
committed
fix: set/unset props based on condition
- the options prop was not getting set on block when its conditionally shown
1 parent d4072c9 commit f32a906

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

frontend/src/components/PropsEditor.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ const componentProps = computed(() => {
130130
const filteredProps: typeof propConfig = {}
131131
132132
Object.entries(propConfig).forEach(([propName, config]) => {
133-
const isVisible = config.condition ? config.condition(currentProps) : true
134-
if (!isVisible) return
133+
const showProp = config.condition ? config.condition(currentProps) : true
134+
if (!showProp) {
135+
props.block?.removeProp(propName)
136+
return
137+
}
135138
136139
if (props.block?.componentProps[propName] === undefined) {
137140
const defaultValue = typeof config.default === "function" ? config.default() : config.default
138141
config.modelValue = defaultValue
142+
if (defaultValue !== undefined) {
143+
props.block?.setProp(propName, defaultValue)
144+
}
139145
} else {
140146
config.modelValue = props.block.componentProps[propName]
141147
}

frontend/src/data/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const COMPONENTS: FrappeUIComponents = {
367367
options: {
368368
required: false,
369369
type: Array,
370-
default: ["John Doe", "Jane Doe"],
370+
default: () => ["John Doe", "Jane Doe"],
371371
condition: (state: Record<string, any>) => state.type === "select" || state.type === "autocomplete"
372372
}
373373
},

frontend/src/utils/block.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ class Block implements BlockOptions {
551551
this.componentProps[propName] = value
552552
}
553553

554+
removeProp(propName: string) {
555+
delete this.componentProps[propName]
556+
}
557+
554558
// component slots
555559
initializeSlots() {
556560
Object.entries(this.componentSlots).forEach(([slotName, slot]) => {

0 commit comments

Comments
 (0)