diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts index 925adba064..d36d47d3ff 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts @@ -419,9 +419,9 @@ export class TbDeviceInstallDialogComponent extends DialogComponent> = {}; - // form-field key → declared type. Used by resolveTemplateJson() to emit BOOLEAN/INTEGER + // form-field key → definition. Its type lets resolveTemplateJson() emit BOOLEAN/INTEGER // placeholders as raw JSON values instead of quoted strings. - private fieldTypes = new Map(); + private formFieldDefs = new Map(); // Transport whose ${.host} the transport host field overrides private hostFieldProtocol: DeviceConnectivityProtocol | null = null; gatewayDockerComposeContent: string | null = null; @@ -947,7 +947,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent = this.entityOutputs): string { return content.replace(/\$\{([^}]+)}/g, (_match, key) => { const res = this.resolveVariable(key, outputs); - if (res) { + if (this.isResolved(key, res)) { return escape(res); } return '${' + key + '}'; @@ -956,7 +956,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent = this.entityOutputs): string | undefined { if (key in this.formValues) { - return String(this.formValues[key]); + return String(this.formValues[key] ?? (this.formFieldDefs.get(key)?.type === FormFieldType.BOOLEAN ? false : '')); } if (this.hostFieldProtocol && key === `${this.hostFieldProtocol}.host`) { const host = toBareHost(String(this.formValues[TRANSPORT_HOST_FIELD_KEY] ?? '')); @@ -1020,7 +1020,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent = this.entityOutputs): any { const typed = raw.replace(/"\$\{([^"{}]+)}"/g, (whole, key) => { - const type = this.fieldTypes.get(key); + const type = this.formFieldDefs.get(key)?.type; if (type !== FormFieldType.BOOLEAN && type !== FormFieldType.INTEGER) { return whole; } @@ -1042,9 +1042,21 @@ export class TbDeviceInstallDialogComponent extends DialogComponent JSON.stringify(value).slice(1, -1), outputs)); } + /** + * An optional text field left empty is resolved, e.g. no Wi-Fi password for an open network. Any other empty value + * keeps its placeholder, so a missing value stays visible. + */ + private isResolved(key: string, res: string | undefined): boolean { + if (res) { + return true; + } + const field = this.formFieldDefs.get(key); + return res === '' && !!field && !field.required && field.type !== FormFieldType.INTEGER && field.type !== FormFieldType.BOOLEAN; + } + private _resolveMarkdownVariable(key: string): string | undefined { const res = this.resolveVariable(key); - if (res) { + if (this.isResolved(key, res)) { return res; } // Special action placeholders @@ -1324,7 +1336,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent locked.has(field.key) ? { ...field, readOnly: true, resettable: false } : field); } for (const field of ws.formFields) { - this.fieldTypes.set(field.key, field.type); + this.formFieldDefs.set(field.key, field); const validators = []; if (field.required) { validators.push(Validators.required); diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-markdown.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-markdown.component.ts index 4bdfabf879..3c34256100 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-markdown.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-markdown.component.ts @@ -229,7 +229,7 @@ export class TbIotHubMarkdownComponent implements OnInit, OnChanges { // Special variables const res = this.onResolveVariable(key); - if (res) { + if (res !== undefined) { return res; } return '${' + key + '}';