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
8 changes: 8 additions & 0 deletions examples/01_Widgets/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from trame.widgets import simput, html

from trame_simput import get_simput_manager
from trame_simput.core.domains import PropertyDomain, register_property_domain


class ConditionalShowDomain(PropertyDomain):
def available(self):
return [{"text": "A", "value": "A"}, {"text": "B", "value": "B"}]


client_type = "vue3"
use_client2 = client_type == "vue2"
Expand All @@ -28,6 +35,7 @@
DEF_DIR = Path(__file__).with_name("definitions")

simput_manager = get_simput_manager()
register_property_domain("ConditionalShowDomain", ConditionalShowDomain)

# -----------------------------------------------------------------------------
# Application state
Expand Down
12 changes: 12 additions & 0 deletions examples/01_Widgets/definitions/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,15 @@ Slider:
- type: UI
properties:
sizeControl: true

Show:
ConditionnalShowInUIMode:
_label: Show second TextField if 'A' or 'B' is typed here
type: string
domains:
- type: ConditionalShowDomain
name: ConditionalShowDomain

ConditionnalField:
_label: Conditionnal show (in UI mode only)
type: string
12 changes: 12 additions & 0 deletions examples/01_Widgets/definitions/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@
</row>
</col>
</ui>
<ui id="Show">
<col>
<row class="mb-2">
<input name="ConditionnalShowInUIMode" />
</row>
<row>
<show property="ConditionnalShowInUIMode" domain="ConditionalShowDomain" style="width: 100%;">
<input name="ConditionnalField" />
</show>
</row>
</col>
</ui>
</layouts>
9 changes: 6 additions & 3 deletions vue3-components/src/widgets/Show/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ export default {
const properties = inject("properties");
const domains = inject("domains");

const visible = computed(() => {
const isVisible = function isVisible() {
this.mtime; // eslint-disable-line
const domain = domains()?.[props.property]?.[props.domain];
const propertyValue = properties()?.[props.property];
if (!domain) {
// no domain == valid
return true;
}
return domain.value.value;
});
return domain.available.map((v) => v.value).includes(propertyValue);
}

const visible = computed(isVisible);

return {
visible,
Expand Down