enable UI options based on number of provided variables

Everything related to the development of modules in jamovi
Post Reply
DStuder
Posts: 16
Joined: Wed Jun 07, 2023 8:07 am

enable UI options based on number of provided variables

Post by DStuder »

Hi there

For one of the tests in my module, the user can provide either one or two grouping variables. I'd like to disable some options of the UI, if only one grouping variable is provided.
I tried the following, but it doesn't work:

Code: Select all

 enable: (`length(self$options$groupingVar) == 2`)
I know it could probably be done with JS, but I don't know any JS and I'd rather not try.

Thanks for any help!
Best, Dan
User avatar
jonathon
Posts: 2840
Joined: Fri Jan 27, 2017 10:04 am

Re: enable UI options based on number of provided variables

Post by jonathon »

regrettably, that would require JS ...

let me attend damo to this, he might be able to provide you with a snippet.

jonathon
DStuder
Posts: 16
Joined: Wed Jun 07, 2023 8:07 am

Re: enable UI options based on number of provided variables

Post by DStuder »

Hi jonathon

I feared as much.

Just so that it doesn't take up too much time... I can also live with displaying a warning in the output. But if you have something similar already, I'm very grateful.

Best wishes,
Dan
dropmann
Posts: 84
Joined: Thu Feb 02, 2017 10:26 am

Re: enable UI options based on number of provided variables

Post by dropmann »

Hi Dan, I can look into providing something for you however it won't be until later this week. It will require some js and I can only provide a file that you will need to modify for your exact purposes, but I'm sure you'll figure it out. I'll let you know when it's ready.

Damian
DStuder
Posts: 16
Joined: Wed Jun 07, 2023 8:07 am

Re: enable UI options based on number of provided variables

Post by DStuder »

Hi Damian, thank you so much!

Best wishes, Dan
jcthrawn
Posts: 5
Joined: Fri Jul 26, 2024 1:49 pm

Re: enable UI options based on number of provided variables

Post by jcthrawn »

Hi everybody,

I would also be interested by the answer : I'm trying to write a javascript to disable some RadioButtons when no Variables of some kind are supplied, but I'm not good at js and nothing seems to work yet.

Brice
DStuder
Posts: 16
Joined: Wed Jun 07, 2023 8:07 am

Re: enable UI options based on number of provided variables

Post by DStuder »

Hi Brice

Haven't heard back from Damian yet. I tried to do it on my own, but that hasn't been successful, so sadly I can't help you out.

Dan
dropmann
Posts: 84
Joined: Thu Feb 02, 2017 10:26 am

Re: enable UI options based on number of provided variables

Post by dropmann »

Hey everyone, I have come up with a solution which i am currently implementing which will provide you with a simple way of doing this without a js file. I should have it done in the next few days. Thanks for your patience.
dropmann
Posts: 84
Joined: Thu Feb 02, 2017 10:26 am

Re: enable UI options based on number of provided variables

Post by dropmann »

Ok. So a new version of jamovi (2.6.11) has been uploaded that allows for more complicated conditions in the u.yaml. Essentially it enables the use of javascript in the u.yaml for some properties. For example, the current system (which continues to function) might look like this

Code: Select all

enable: (postHocES:d)
where postHocES is of type NMXList, which means its value is an array of options. This 'enable' property example could now also be expressed in javascript as

Code: Select all

enable: ({ return ui['postHocES'].value()?.includes('d'); })
Obviously in the above example, the former is more concise and should be used, however, it can be seen that any javascript can be used as long as it returns the appropriate type for the option property.

In regards to the initial inquiry, the following can be used.

Code: Select all

 enable: ({ return ui['groupingVar'].value()?.length == 2; })
The ? is an optional chaining operator and is needed because the value of ui['groupingVar'].value() can be null and therefore an exception is avoided if it is the case.

Currently options need to be referred to using single quotation marks in the following form ui['optionName'].value()

If there are any questions or issues please let me know.
DStuder
Posts: 16
Joined: Wed Jun 07, 2023 8:07 am

Re: enable UI options based on number of provided variables

Post by DStuder »

Wow Damian this is mighty impressive! Thank you so much for your help, I really appreciate it. Got my UI working as I intended now :)
Post Reply