2

My button has to enable when I fill my input. Currently it keeps being disabled.

HTML button:

<button pButton type="button" class="buttonCSS" [disabled]="buttonDisabled" label="Boeken" id="button" (click)="on_Boek()"></button>

HTML input

<input type="text" [(ngModel)]="sBoekOmschrijving" (onchange)="on_ChangeInput()" pInputText/>

TypeScript function

on_ChangeInput()
{
 this.buttonDisabled = false 
}

Typescript button disabled always true

buttonDisabled = true

Most likely a stupid question.. but I really can't figure it out.. thanks anyway. I am not allowed to use Jquery.

1

1 Answer 1

2
  • onchange are for selects, not inputs
  • (onchange) doesn't exist in Angular (it's change)
  • (input) could do the trick

But the best solution would be :

<button pButton type="button" class="buttonCSS" [disabled]="!sBoekOmschrijving" label="Boeken" id="button" (click)="on_Boek()"></button>
<input type="text" [(ngModel)]="sBoekOmschrijving" pInputText/>

By relying on falsy values, you put the condition

Disable the button if the sBoekOmschrijving field has no value

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help, both (input) and [disabled]="!sBoekOmschrijving" did the trick. P.S. Our boss used (onchange) in projects, but thansk for your advice being it (change)
@Undertaked onchange is a Javascript binding, If you use Angular and want to bind to your component, you remove the "on" : onclick → (click), onchange → (change) ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.