You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setDisabledState() never called when receiving disabled state from master fieldset #13856
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The setDisabledState() method is never called when disabled state change is propagated from the master fieldset.
Expected behavior
The method should be called when a change in disabled state occurs. This should not require feeding the state to a control's @Input()
What is the motivation / use case for changing the behavior?
The hook should be fired in order to provide parallel render and behavior to what is happening on the browser level, as per: https://www.w3.org/wiki/HTML/Elements/fieldset
I am running into this same issue now. Any idea when it might be fixed? or if there is a suggested work around to make ControlValueAccessor respond to fieldsets disabled state as described above?
I haven't really pursuited or tested it but you might try to make an
attribute directive for fieldsets and have it emit an event when the
disabled prop/attribute changes. Might work. Might not. Worth trying.
On Mon, Feb 12, 2018, 23:18 Tim Barber ***@***.***> wrote:
I am running into this same issue now. Any idea when it might be fixed? or
if there is a suggested work around to make ControlValueAccessor respond to
fieldsets disabled state?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AApn5OnoUlz6vPKs9us69dtqBwzG6HOdks5tULisgaJpZM4LfOx3>
.
I was able to get this working (although its not ideal) by itself:
import{Directive,EventEmitter,HostBinding,Input,OnInit,Optional,Self,SkipSelf}from'@angular/core';import{NgControl,NgForm}from'@angular/forms';/** * Directive for forcing synchronization of disabled states between form elements suchs as NgForm, fieldset, and NgModel */
@Directive({selector: 'form,fieldset,[formControlName],[formControl],[ngModel]'})exportclassDisabledSynchronizationDirectiveimplementsOnInit{/** * Indicates that this fieldset is disabled */
@Input()
@HostBinding('class.disabled')
@HostBinding('attr.disabled')
@HostBinding('attr.aria-disabled')publicgetdisabled(): boolean{returnthis.selfIsDisabled;}publicsetdisabled(value: boolean){// translate false to 'null'. Why: attr bindings will remove the attribute if it returns null, but false will result in // [disabled="false"] in the case of disabled attr, we actually do want to remove them.// see thread: https://github.com/angular/angular/issues/2869this.selfIsDisabled=value||null;this.updateDisabledState();}/** * Indicates that this instance or its parent instance is disabled */privategetisDisabled(){return!!this.selfIsDisabled||this.parentIsDisabled;}/** * Indicates that the parent directive is disabled */privategetparentIsDisabled(){return!!this.parent&&this.parent.isDisabled;}/** * EventEmitter for disabled state changes */
@Output()publicdisabledChanges: EventEmitter<boolean>=newEventEmitter<boolean>();/** * Placeholder for disabled accessor */privateselfIsDisabled: boolean;/** * Indicates if this was already disable on the previous update (in which case we do not need to fire again) */privatepreviousIsDisabled: boolean;/** * Constructs a new instance of DisabledSynchronizationDirective */constructor(
@Optional() @SkipSelf()privateparent: DisabledSynchronizationDirective,
@Optional() @Self()privatengControl: NgControl,
@Optional() @Self()privatengForm: NgForm){}/** * Implementation of angular OnInit interface */publicngOnInit(){if(this.parent){this.subscriptions.push(this.parent.disabledChanges.subscribe(()=>this.updateDisabledState()));}}/** * updates the disabled state of the form controls attached to this element */privateupdateDisabledState(){// dont fire if nothing has really changedif(this.previousIsDisabled===this.isDisabled){return;}// notify others that state has changedthis.disabledChanges.next(this.isDisabled);// either disable or enable related controlsletmethod=this.isDisabled ? 'enable' : 'disable';// handle ngForm if this element has a form referenceif(this.ngForm){this.ngForm.control[method]();}// handle ngControl if this element has a reference to itif(this.ngControl){this.ngControl.control[method]();}// Save disabled state for next timethis.previousIsDisabled=this.isDisabled;}}
Now I have a problem that this doesn't work in one particular use case where I have a template for the content of my fieldset defined inside of my ControlValueAccessor. This looks like:
The inputs instance of DisabledSynchronizationDirective will find the DisabledSynchronizationDirective instance on the myControlValueAccessor as 'parent' and not the fieldset.
I disagree with this being labeled a "feature" as well as the sev rating. As you can see from the linked issues, it's resulting in bug reports in other projects. It flat-out doesn't work the way one would expect, and breaks established semantics that apply to forms.
Reacted by Jonathon Wyza, Mladen Brndušić, Miloš Danilov, WuWen, LuqJensen, wendellestradairely and mnch
I can confirm that this issue persists on angular 5.2.10. I agree with @MattHoneycutt that this should be labeled as a bug, because it breaks usage in angular/material.
@kara do you agree, that this should be labeled as a bug and not feature?
Reacted by Mladen Brndušić, be4code, Alec Custer, WuWen, LuqJensen and mnch
Hi, it looks like this issue has the same root cause as #35309, so I'm closing this PR in favor of #35309 (so all similar issues are grouped). Thank you.
Activity
moniuch commentedon Jan 23, 2018
Why is this ticket flagged as a feature? The fieldsets cannot be used according to W3C specs. It is a bug. It breaks intrinsic in-browser behavior.
RedBati commentedon Feb 12, 2018
I am running into this same issue now. Any idea when it might be fixed? or if there is a suggested work around to make ControlValueAccessor respond to fieldsets disabled state as described above?
moniuch commentedon Feb 12, 2018
RedBati commentedon Feb 13, 2018
I was able to get this working (although its not ideal) by itself:
Now I have a problem that this doesn't work in one particular use case where I have a template for the content of my fieldset defined inside of my ControlValueAccessor. This looks like:
but when i use it like this:
The inputs instance of DisabledSynchronizationDirective will find the DisabledSynchronizationDirective instance on the myControlValueAccessor as 'parent' and not the fieldset.
MattHoneycutt commentedon Apr 19, 2018
I disagree with this being labeled a "feature" as well as the sev rating. As you can see from the linked issues, it's resulting in bug reports in other projects. It flat-out doesn't work the way one would expect, and breaks established semantics that apply to forms.
brndusic commentedon May 16, 2018
I lost hours trying to find out problems in my implementation. Please fix this and flag it as a bug. This also worked in AngularJS.
milosdanilov commentedon May 16, 2018
I can confirm that this issue persists on angular 5.2.10. I agree with @MattHoneycutt that this should be labeled as a bug, because it breaks usage in angular/material.
@kara do you agree, that this should be labeled as a bug and not feature?
kolkov commentedon Jun 9, 2018
Not working for me too in Angular 6.0.4 :((
kolkov commentedon Jun 9, 2018
Sorry... changing [attr.disabled] to [disabled] worked for me now.
LuqJensen commentedon Mar 30, 2020
This is causing problems for me on Angular 9 in 2020 too
wendellestradairely commentedon Sep 4, 2020
I'm also having this issue in Angular 10. Man it's already version 10 and in pandemic year 2020 and still hasn't been fixed.
AndrewKushnir commentedon Nov 17, 2020
Hi, it looks like this issue has the same root cause as #35309, so I'm closing this PR in favor of #35309 (so all similar issues are grouped). Thank you.
angular-automatic-lock-bot commentedon Dec 19, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.