0

How to disable the below div when this length condition satisfies. Please check and help me..

<div *ngIf="setUpWizardForm.get('projectTitle').value && slpPlat && (setUpWizardForm.get('projectTitle').value.length + slpPlat.length) > 50" >
    <span 
        class="error-message" 
        style="padding-left:15px;"
    > 
        Project Name - maximum of 50 characters allowed 
    </span>
</div>

<!-- Here want to disable that div in below button. Please help -->

<button 
    href="javascript:void(0);" 
    class="slm-user-action-btn" 
    [disabled]='setUpWizardForm.invalid || !projectNameFilled' 
    *ngIf="currentSlide==3" 
    type="button" 
    (click)="projectConfigured(templateInProcess)"
> 
    Configure
</button>
Leonardo
  • 2,350
  • 14
  • 15
  • 30
venusri
  • 5
  • 3

1 Answers1

0

To disable button when characters exceeds in projectTitle field and using suffix as slpPlat we can do in below manner :

  1. Keep a onChange() function on your input type projectTitle. So it will be something like <input name="projectTitle" onChange="checkFieldLen()" />
  2. Now in this function as well as on ngAfterViewInit() hook need to calculate length for the input fields.
  3. You can access input element in your .ts file using ElementRef (How to get ElementRef reference from NgModel FormControl in NgForm in Angular 4+)
  4. Now check the length including suffix at both the places and toggle the boolean variable to enable/disable the button
PHP Team
  • 3,667
  • 1
  • 13
  • 23