question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it compulsory to pass {value, disabled} to FormControl

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/....

Is this a regression?

Yes, the previous version in which this bug was not present was: .... No Idea

Description

I am getting object object in input control but if i pass disabled key in FormControl then it works.

Expected: disabled key should be optional by default it will be false.

πŸ”¬ Minimal Reproduction

Stackblitz: https://stackblitz.com/edit/angular-uxlh5z?file=src%2Fapp%2Fapp.component.ts

code:

      this.myForm = new FormGroup(
      {
        test: new FormControl({ value: "Husky" }, [
          Validators.required
        ])
      },
      // this will work if i pass disabled key
     /*  {
        test: new FormControl({ value: "Husky", disabled: true }, [
          Validators.required
        ])
      }, */
      { updateOn: "blur" }
    );

image

πŸ”₯ Exception or Error






🌍 Your Environment

Angular Version:




 "@angular/common": "^8.0.0",
    "@angular/compiler": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/forms": "^8.0.0",
    "@angular/platform-browser": "^8.0.0",
    "@angular/platform-browser-dynamic": "^8.0.0",
    "@angular/router": "^8.0.0",
    "core-js": "2",
    "rxjs": "^6.5.2",
    "zone.js": "^0.9.1"

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewKushnircommented, May 27, 2020

Hi @indraraj26, thanks for the reply. I think changing this logic might be tricky and will result in a breaking change. We should probably start with the documentation update and revisit this in the future (to see if there is a better way to package value and disabled state). Thank you.

1reaction
StrangeAmeycommented, Mar 1, 2020

@indraraj26 You Can directly assign the value like this also as a string this.myForm = new FormGroup( { test: new FormControl(β€œHusky”, [ Validators.required ]) },

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Input fields in reactive form - angular - Stack Overflow
I tried to do the following: form = new FormGroup({ first: new FormControl({value: '', disabled: true}, Validators. required), }); not working!
Read more >
Exploring the difference between disabling a form control ...
We've given the form controls default values, disabled both the controls and required the firstName control by having a required validator on its...
Read more >
Disable Angular FormControl - ConcretePage.com
We can disable a FormControl by passing disabled attribute while instantiating it. We can use disable() and enable() method of FormControl.
Read more >
Disabling Form Controls When Working With Reactive Forms ...
Instantiate a new FormControl with the disabled property set to true. FormControl({value: '', disabled: true}) . Calling control.disable() or control.enable() .
Read more >
aria-disabled - Accessibility - MDN Web Docs
If you are purposefully using the aria-disabled attribute to allow for a form control to remain in the page's keyboard focus order, particularlyΒ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found