Page 1 of 1
enable UI options based on number of provided variables
Posted: Thu Jul 11, 2024 1:42 pm
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
Re: enable UI options based on number of provided variables
Posted: Fri Jul 12, 2024 12:21 am
by jonathon
regrettably, that would require JS ...
let me attend damo to this, he might be able to provide you with a snippet.
jonathon
Re: enable UI options based on number of provided variables
Posted: Fri Jul 12, 2024 4:38 am
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
Re: enable UI options based on number of provided variables
Posted: Sun Jul 14, 2024 4:56 am
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
Re: enable UI options based on number of provided variables
Posted: Sun Jul 14, 2024 6:30 am
by DStuder
Hi Damian, thank you so much!
Best wishes, Dan
Re: enable UI options based on number of provided variables
Posted: Fri Aug 02, 2024 1:44 pm
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
Re: enable UI options based on number of provided variables
Posted: Thu Aug 29, 2024 10:57 am
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
Re: enable UI options based on number of provided variables
Posted: Tue Sep 10, 2024 12:18 am
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.
Re: enable UI options based on number of provided variables
Posted: Wed Sep 11, 2024 11:50 pm
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
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.
Re: enable UI options based on number of provided variables
Posted: Thu Sep 12, 2024 6:26 am
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
