Default Value for widget properties

Im looking for a way to define a default value for properties in custom widgets.

I see the “workaround” @RGroll is using in the weather widget.

"=(!props.itemPrefix) ? items.UVIndex.state : 'UV Index: ' + items[props.itemPrefix + 'UVIndex'].state 

My goal is to define the default value in the parameter section (props) for a better structure:

uid:
props:
  parameters:
    - description: <b>Optional prefix</b> for item names.
      label: Item prefix
      name: itemPrefix
      type: TEXT
      default: myDefaultValue      

But unfortunately, there is no parameter “default” in the docs:
https://www.openhab.org/docs/developer/bindings/config-xml.html

<parameter name="String" type="{text|integer|decimal|boolean}" min="Decimal" max="Decimal" step="Decimal" pattern="String" required="{true|false}" readOnly="{true|false}" multiple="{true|false}" groupName="String" unit="A|cd|K|kg|m|mol|s|g|rad|sr|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|Cel|lm|lx|Bq|Gy|Sv|kat|m/s2|m2v|m3|kph|%|l|ms|min|h|d|week|y">
      <context>{network-address|serial-port|password|password-create|color|date|datetime|email|month|week|dayOfWeek|time|tel|url|item|thing|group|tag|service|channel|rule|location}</context>
      <required>{true|false}</required>
      <default>String</default>
      <label>String</label>
      <description>String</description>
      <unitLabel>String</unitLabel>
      <options>
        <option value="String">String</option>
      </options>
      <filter>
        <criteria name="String">String</criteria>
      </filter>
    </parameter>

By the way: what does this stands for:

<default>String</default>

What do you think about adding just an additional parameter “default”?

<parameter name="String" default="String" type="{text|integer|decimal|boolean}" min="Decimal" max="Decimal" step="Decimal" pattern="String" required="{true|false}" readOnly="{true|false}" multiple="{true|false}" groupName="String" unit="A|cd|K|kg|m|mol|s|g|rad|sr|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|Cel|lm|lx|Bq|Gy|Sv|kat|m/s2|m2v|m3|kph|%|l|ms|min|h|d|week|y">
      

Would this cause problems and would it be hard to implement?

We’re on the same page here → Default values for widget property parameters · Issue #990 · openhab/openhab-webui · GitHub

Dammit, I haven’t seen that at all and Google didn’t told me even after 5h of search yesterday.

so that this topic here is not completely useless, can you shoot out a short answer for my last questions?

I did the same workaround for my widget

Actually is you leave it as items you can set it as the things default widget and as long as long as the items follow the same name they will all show up.

Haven’t seen this workaround. Nice.

But after all it’s another workaround. Same as the - - f7-…-thing. There are other workarounds too.

I don’t have the full overview but I think implementing another parameter property won’t be a huge issue for the maintainer (who are doing a great job by the way :+1:).
at the same time it would make it easier to build customizable custom-widgets and much easier to use and adjust those which is a big advantage for all openhab users

you can add default values to your widget’s props:

uid:
props:
  parameters:
    - description: <b>Optional prefix</b> for item names.
      label: Item prefix
      name: itemPrefix
      type: TEXT
      defaultValue: whatever

why does that not help?

It’s not working in my case. If I open the “set props” handler, the field for itemPrefix is filled with the defined defaultValue but…

- component: Label
      config:
        text: =props.itemPrefix

… just gives me an “undefined”. If I manually change the value in the “set props” handler, this label shows the defined value/text

yes. that“s how I do it also. add a space character and delete it, so that it gets flagged as dirty and being recognized

In my point of view this could be unnecessarily confusing for the regular user.
If there is a value shown in the input box, this value should exactly be recognized by the software/application /widget (automatically).