I have an input field and a button. It must be disable at start. When the input no blank is, the button is enable.
I use a ngModel to take the value of the input and a function (change) to start a function each time the input is changed.
Now I do a little if in the change function.
if(input !== ''){
//enable the button
}else{
//disable the button
}
Have you any idea how to achieve that?
Thanks
To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .
How do you disable button until all fields are entered? Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.
It is of the boolean datatype, the default value is true. Angular PrimeNG Focus Trap Disabled Button properties: disabled: It specifies the button to be disabled if the value is set to true. The default value is false.
Just have a boolean variable in class:
isenabled:boolean=false;
Change function
if(input !== ''){
//enable the button
isenabled=true;
}else{
//disable the button
isenabled=false;
}
In Html:
<button ion-button [disabled]="!isenabled"></button>
For changing classes:
<button ion-button [ngClass]="{class:isenabled,class2:!isenabled}"></button>
Check here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With