How are defaultValues in hjson connected to default values in component attributes?

I'm not fully understanding the defaults between hjson and js files for custom app connect components. Can someone explain the difference and how they are related?

Why do we need to define them in two places?

hjson for component
image

js file where dmx.Component is defined
image

If I understand your question, then the following:

  • JS, along with HTML and CSS, is used for the widget to function.
  • HJSON is used to encapsulate this widget for App Connect.

Hey Ben,

The documentation for hjson shows adding default values.

image

Th deafultValue appears when the component is rendered in Wappler editor.
image

But, we also have the ability to set a default in the js file where we create the runtime component.

image

So, if I define a default in hjson how do I get it to appear at runtime?

The default in HJSON is cosmetic, the code gets an empty value. I don't know if it's an empty string, null or undefined value. I also don't know if the default value in the code is used, or it if it's overwritten by the empty value coming from the caller. I'm also not familiar with the situation in question and my knowledge is inferred from Wappler server-side extensions

The technique used to give a value to a falsy (empty) value is:

let x = null || 'default'

This is what I have done for the YouTube Player

image

image

And for the runtime

As you can see, I have left the default a blank.

Have a look at the other App Connect extensions to see how others have done this. A very interesting one is

ok, the hjson defaultValue can be used with this.props.[propertyname] in the js file.

Example: this.props.placeholder

But, I still don't understand the default set in the property that is set in the dmx.Component

image

ok, it's starting to make sense.

The default set in the js file is overridden if you set a defaultValue in the hjson.

So it's one or the other.

Both are accessed using this.props.[propertyname]

The defaultValue from the hjson will show in the field within Wappler App Structure when you add the component, but the default from the js does not. It will only work at runtime.


If would be helpful if this was added to the documentation at the below locations.

2 Likes