openhab-webui icon indicating copy to clipboard operation
openhab-webui copied to clipboard

Widget Editor saves default props incorrectly causing widget failure

Open Mark-VG opened this issue 2 years ago • 2 comments

The problem

When creating a widget using the built in widget editor, the value for default in props is saved incorrectly as "8" instead of 8 when exiting and re-entering the widget editor. This causes unexpected results when using for example oh-repeater.

uid: repeater_range_with_props
tags: []
props:
  parameters:
    - default: 8
      description: Numbers of Partitions in System
      label: Numbers of Partitions in System
      name: numberPartitions
      required: true
      type: INTEGER
  parameterGroups: []
timestamp: Aug 24, 2022, 3:40:02 PM
component: f7-block
config: {}
slots:
  default:
    - component: f7-row
      slots:
        default:
          - component: oh-repeater
            config:
              fragment: true
              sourceType: range
              for: partition
              rangeStart: 1
              rangeStop: =props.numberPartitions
            slots:
              default:
                - component: f7-row
                  slots:
                    default:
                      - component: oh-button
                        config:
                          text: =["P" + loop.partition]
                          fill: true
                          textColor: white

Works correctly and produces image

However when exiting and re-entering the widget editor the code appears as:

uid: repeater_range_with_props
tags: []
props:
  parameters:
    - default: "8"
      description: Numbers of Partitions in System
      label: Numbers of Partitions in System
      name: numberPartitions
      required: true
      type: INTEGER
  parameterGroups: []
timestamp: Aug 24, 2022, 6:51:52 PM
component: f7-block
config: {}
slots:
  default:
    - component: f7-row
      slots:
        default:
          - component: oh-repeater
            config:
              fragment: true
              sourceType: range
              for: partition
              rangeStart: 1
              rangeStop: =props.numberPartitions
            slots:
              default:
                - component: f7-row
                  slots:
                    default:
                      - component: oh-button
                        config:
                          text: =["P" + loop.partition]
                          fill: true
                          textColor: white

And results in: image

There are 10x the number of members to the repeater that there should be. I have also noticed that if the default value is left off, there are 10 repeater members by default.

The end result is that the default value in this case has no effect.

Expected behavior

I would expect that the default value is saved in the format:

props:
  parameters:
    - default: 8

and not:

props:
  parameters:
    - default: "8"

Which seems to be the case for anything other than numbers.

Steps to reproduce

Save the above widget in widget editor. This will be done with the "8". The result will be an 80 member loop.

Edit the Properties and change the default value to be 8 (with no ""). The resultant repeater will have the expected 8 members.

Exit and re-enter the widget editor and see that the default has been reverted to "8" with the 80 member repeater.

Your environment

openHAB 3.4.0.M1

Mark-VG avatar Aug 24 '22 17:08 Mark-VG

Prop parameters are serialized as ConfigDescriptionParameter in the JSONDB and thus default values are always Strings: https://www.openhab.org/javadoc/latest/org/openhab/core/config/core/configdescriptionparameter#getDefault()

So it's not an issue with the UI per se - not necessarily unfixable but this is the wrong repo.

You could use:

              rangeStop: =Number.parseInt(props.numberPartitions)

in your oh-repeater.

ghys avatar Aug 24 '22 18:08 ghys

Thank you Yannick. Your response is greatly appreciated. Your solution works nicely, so thanks.

Just to confirm, based on "So it's not an issue with the UI per se - not necessarily unfixable but this is the wrong repo.", do you suggest I relog under core (or would that just be a waste of everyone's time)? Considering that your solution resolves the issue I experienced.

And have I logged my other request incorrectly as well? https://github.com/openhab/openhab-webui/issues/1471

Many thanks Mark

Mark-VG avatar Aug 25 '22 05:08 Mark-VG