0

I have a reactive form trainingFeedbackForm with a textarea:

<textarea pInputTextarea appWhiteSpace inputField="{{not_attended_reason}}"
    [(ngModel)]="not_attended_reason" [disabled]="attended==='yes'"
    placeholder="The reason for not attending the traning"
    (inputValue)="removeWhitespace($event)"></textarea>

I want to disable this button when either the form is valid or the textarea is empty:

<button (click)="getFeedbackFormValue()" class="btn-gradient fill-btn ripple"
    [disabled]="trainingFeedbackForm.invalid || !not_attended_reason">
    Submit feedback
</button>

The approach I am using above is not working.

How can I achieve this? Can somebody help?

plr108
  • 1,201
  • 11
  • 16
juhi
  • 558
  • 1
  • 10
  • 19

2 Answers2

0

component.html in Replace disabled="checkDisbled()" this

add required in <textarea required>

<button (click)="getFeedbackFormValue()" class="btn-gradient fill-btn ripple"
                disabled="checkDisbled()">
                Submit feedback
              </button>

Add in Component.ts file

checkDisbled(){
  if(this.trainingFeedbackForm.invalid){ // <- add number of validation
  return true;
  }
  else {
  return false;
  }
}
Vijay Prajapati
  • 738
  • 1
  • 7
  • 20
0

This should do the trick, just added !trainingFeedbackForm.invalid

<button (click)="getFeedbackFormValue()" class="btn-gradient fill-btn ripple"
[disabled]="!trainingFeedbackForm.invalid">
Submit feedback
</button>

Also, make sure that you add Validators.required to each form in your .ts

Omar
  • 212
  • 6
  • 17