Disable a Oh-button

Hi, is there a way to disable a oh-button in mainUI, so that users cannot push this button when it is disabled? I tried also to define a custom widget, but I don’t find any option to disable the button. Many thanks for your help.

You can add disabled property to the button config. If the property evaluates to true, the button will be disabled.

Thank you very much.

At the end I managed to make the button completely invisible dynamically, with this code in a custom widget: visible:

component: oh-button
visible: “=(items[props.myitem].state === ‘ON’) ? false : true”

I tried also with “disabled”, but it was not working dynamically in a custom widget with props. In any case “disabled” works well if you don’t need to make it dynamic, so thank you very much for your reply.

disabled works with all the same dynamic expression that hidden does. If your expression works for one it will work for the other.

If you’d like to make this a little cleaner you can simplify it some. The expression does not have to be of the form =(test) ? if true : if false it just has to evaluate to either true or false which is already being done by the first part. In this case you want the value to be false when the state is ON (true) so you just need to use the not operator which is !. This should do the trick:

visible: =!(items[props.myitem].state == 'ON')
1 Like

Thanks for the suggestions!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.