I have one input textbox and and a text area in a form. If I click on textarea I need to validate input textbox is not empty, if empty, the text area should be disabled and I should show a validation message in below the input text field.
onClickvalidate(name: string) {
this.noContentError = "";
this.noName = name;
if (this.noName == '') {
this.noContent = true;
//this.noContentError = "Please provide a name."
this.name.setErrors({
noContent: `Please provide a name `
});
} else {
this.noContent = false;
this.name.setErrors(null);
}
}
<div class="row">
<div class="col-md-3">
<label for="name"> Name</label>
<input pInputText class="input" id="name" formControlName="name" placeholder="Name" type="text" />
<div *ngIf="name.invalid && name.touched" class="">
<div *ngIf="this.noContent" class="alert alert-danger alert-duplicate">
{{this.noContentError}}
</div>
</div>
<div class="col-md-6 ">
<label for="content">Input Text</label>
<div class="textarea-content">
<textarea pInputTextarea class="text-area" rows="1" id="content" formControlName="content" [readonly]="!name.value" placeholder="content is required" (click)="onClickvalidate(name.value)" (change)="textFormatting()"></textarea>
<div *ngIf="content.invalid && name.value">
<span *ngIf="!content.value" class="">Content Required</span>
</div>
</div>
</div>
</div>
[disabled]="name.invalid && name.touched"not work as you'd require on the text area?readonlyinstead ofdisabled.