diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html
index 2d992187f6..6f495984f5 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html
@@ -35,7 +35,7 @@
{{ 'gateway.rpc.withResponse' | translate }}
- {{ 'gateway.rpc.responseTopicExpression' | translate }}
+ {{ 'gateway.rpc.responseTopicExpression' | translate }}*
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts
index 2ea5964b84..cbb11fc059 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts
@@ -14,7 +14,7 @@
/// limitations under the License.
///
-import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
+import { Component, EventEmitter, forwardRef, Input, OnDestroy, OnInit, Output } from '@angular/core';
import {
ControlValueAccessor,
FormArray,
@@ -22,6 +22,8 @@ import {
FormControl,
FormGroup,
NG_VALUE_ACCESSOR,
+ UntypedFormControl,
+ ValidatorFn,
Validators
} from '@angular/forms';
import {
@@ -53,6 +55,8 @@ import {
} from '@shared/components/dialog/json-object-edit-dialog.component';
import { jsonRequired } from '@shared/components/json-object-edit.component';
import { deepClone } from '@core/utils';
+import { takeUntil, tap } from "rxjs/operators";
+import { Subject } from "rxjs";
@Component({
selector: 'tb-gateway-service-rpc-connector',
@@ -66,7 +70,7 @@ import { deepClone } from '@core/utils';
}
]
})
-export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValueAccessor {
+export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, ControlValueAccessor {
@Input()
connectorType: ConnectorType;
@@ -105,6 +109,7 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
private propagateChange = (v: any) => {
}
+ private destroy$ = new Subject();
constructor(private fb: FormBuilder,
private dialog: MatDialog,) {
@@ -138,6 +143,17 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
}
});
this.isMQTTWithResponse = this.fb.control(false);
+ this.isMQTTWithResponse.valueChanges.pipe(
+ tap(() => {
+ this.commandForm.get('responseTopicExpression').updateValueAndValidity();
+ }),
+ takeUntil(this.destroy$),
+ ).subscribe();
+ }
+
+ ngOnDestroy(): void {
+ this.destroy$.next();
+ this.destroy$.complete();
}
connectorParamsFormGroupByType(type: ConnectorType): FormGroup {
@@ -148,7 +164,7 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
formGroup = this.fb.group({
methodFilter: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
requestTopicExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
- responseTopicExpression: [null, [Validators.pattern(noLeadTrailSpacesRegex)]],
+ responseTopicExpression: [null, [this.requiredOnWithResponse(), Validators.pattern(noLeadTrailSpacesRegex)]],
responseTimeout: [null, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]],
valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
})
@@ -424,4 +440,16 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
this.commandForm.patchValue(value, {onlySelf: false});
}
}
+
+ private requiredOnWithResponse(): ValidatorFn {
+ return (control: UntypedFormControl) => {
+ const withResponse: boolean = this.isMQTTWithResponse?.value;
+
+ if (withResponse && !control.value) {
+ return { 'required': true };
+ }
+
+ return null;
+ };
+ }
}