Disabled attribute does not work for input and textarea elements if formControlName is set
I'm submitting a ... (check one with "x")
[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports) Please demonstrate your case at stackblitz by using the issue template below. Issues without a test case have much less possibility to be reviewd in detail and assisted.
editor: https://stackblitz.com/edit/github-g6uilx?file=src/app/app.component.html app: https://github-g6uilx.stackblitz.io
Current behavior The disabled attribute does not work for input and textarea elements, if a formControlName is set. (It works fine for other components, e.g. p-calendar or p-inputNumber)
Expected behavior The disabled attribute should work for input and textarea elements if a formControlName is set as well.
Minimal reproduction of the problem with instructions see stackblitz link
Hi.
When works with reactive forms, the best way to handler disable controls is set de property in the formControl definition.
Modify your stackblitz code to show you an example. https://stackblitz.com/edit/github-g6uilx-zbqjux?file=src%2Fapp%2Fapp.component.ts
I hope this can help you.
@alexrponce Thanks for your answer. I know that it's recommended to set the disabled flag via code but the [disabled] property of the control should work anyway. It works for all other primeng form controls I tested, so it's a bug in my eyes.
Angular even displays a warning in the console:
It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
you. We recommend using this approach to avoid 'changed after checked' errors.
Example:
form = new FormGroup({
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
last: new FormControl('Drew', Validators.required)
});
In other words, Angular recommends that you not use the disabled attribute when using reactive forms.
key word being recommends, this should still work, setting the disabled value in the FormControl definition does not react to changes if you use an expression to return true/false like it does when using the [disabled] attribute
Hi,
So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!
Best Regards,