openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
218 stars 239 forks source link

[webui]Extend props. default value to vars. #1471

Open Mark-VG opened 2 years ago

Mark-VG commented 2 years ago

As discussed in https://community.openhab.org/t/oh3-widget-vars-default-value/138318 it is currently not possible to set a default value for a variable in an OH3 widget. Being able to do so would simplify many widgets and remove the need to manually protect against undefined variable son each and every expression.

The props. default value issue was resolved in https://github.com/openhab/openhab-webui/pull/1049/commits/cf7cfd9e5b7d2156f1b55c2c0f67698dade6e00f and it would be great is this could be extended to cater for variables as well.

The following widget code does not work, as the var. default value is not working:

uid: demo:default_vars
tags: []
props:
  parameters:
    - default: This is a default value
      description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Aug 22, 2022, 5:38:10 PM
component: f7-card
config:
  title: =(vars.prop1 || 'No Default Value Set')

The following is the result: image

However when using props. as follows:

uid: demo:default_vars
tags: []
props:
  parameters:
    - default: This is a default value
      description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Aug 22, 2022, 5:38:10 PM
component: f7-card
config:
  title: =(props.prop1 || 'No Default Value Set')

the default value is used and results as follows: image

In my widget I use many vars. expressions as they are carried across to other expressions etc and are changed in the widget, which it appears is not supported with props.

It would be useful to many if the default value could be extended to variables as well as the current props.

Mark-VG commented 1 year ago

I think the following issue could also be resolved if this was working? https://community.openhab.org/t/oh3-widget-popup-with-populated-var-when-called-via-f7-popup-but-not-with-action-popup/142004