Enabling a UI control based on VariablesListBox

Everything related to the development of modules in jamovi
Post Reply
vjalby
Posts: 29
Joined: Tue Oct 24, 2023 4:52 pm
Contact:

Enabling a UI control based on VariablesListBox

Post by vjalby »

It's possible to conditionally enable a UI control using the enable keyword.

But when the condition is "a VariablesListBox is filled", I have to use 2 negations, eg

Code: Select all

enable: (!(!group))
Now, I wonder if there's a way to test (without JS) if a VariablesListBox is filled with more than 1 variable ?
User avatar
NourEdinDarwish
Posts: 26
Joined: Fri Jan 23, 2026 9:14 pm

Re: Enabling a UI control based on VariablesListBox

Post by NourEdinDarwish »

Hi,

I think you can use js code in enable field directly, I used this for example to check that it is filled with at least one variable

Code: Select all

enable: ({return (ui['subgroupVariables'].value() || []).length > 0;})
I think you can replace the 0 with 1 to satisfy this condition of more than one variable

however, I don't know if this is the best practice here, would be great if Jonathan could comment on it, I think the problem with enable field that it has this special syntax with certain heuristics
dropmann
Posts: 89
Joined: Thu Feb 02, 2017 10:26 am

Re: Enabling a UI control based on VariablesListBox

Post by dropmann »

Hi, generally we discourage the use of enabling/disabling options unless it's clear to the user what the relationships is (i.e. a checkbox with nested options underneath it) ... you might be better off running the analysis, and presenting a notice at the top, explaining why an option can't be honoured. ... so think if this is the best approach, but if you did want to do this you could do what NourEdinDarwish suggested but these types of situations usually indicate that design wise something is amiss. It can be tricky.
vjalby
Posts: 29
Joined: Tue Oct 24, 2023 4:52 pm
Contact:

Re: Enabling a UI control based on VariablesListBox

Post by vjalby »

Thank you Nour, that's exactly what I was looking for !

@dropmann, I agree with your comment. I'll use it wisely :)
Post Reply