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.

[disabled] not working for input attached to md-autocomplete

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

When setting [disabled]=“true” on input, the input should be disabled. <input mdInput placeholder="input md-autocomplete" [disabled]="true" [mdAutocomplete]="auto" [formControl]="stateCtrl">

What is the current behavior?

Input is still enabled and user can change it. The browser console shows below warning message:.

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) });

What are the steps to reproduce?

Plunker https://plnkr.co/edit/uQlms4Ok7fMgBNoaTUrO?p=preview

What is the use-case or motivation for changing an existing behavior?

For the dumb user like me, this should work out of box.

Which versions of Angular, Material, OS, browsers are affected?

"@angular/core": "^4.0.3",
"@angular/forms": "^4.0.3",
"@angular/material": "^2.0.0-beta.3",

Is there anything else we should know?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
kamokcommented, Mar 22, 2018

How does one disable the autocomplete if they use template driven forms? My app has a component where I must use template driven forms. The example in the docs uses a FormControl. However, my input uses ngModel instead.

What I’ve tried: @ViewChild(‘employerModel’) employerModel: NgModel; this.employerModel.control.disable();

I expected this to work, since the example does control.disable().

My component does not have any formControl binding in it.

2reactions
meritorcommented, Apr 25, 2017

Thanks @DevVersion for the information. Got a workaround after reading #2667. Use myFormControl.enable() myFormControl…disable() function Here is the example https://plnkr.co/edit/T4Lywt7dj9RROcMn1ZQL?p=preview

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material's mat-autocomplete input is not getting ...
I'm trying to disable an Angular Material ...
Read more >
Autocomplete | Angular Material
Whether the autocomplete is disabled. When disabled, the element will act as a regular input and the user won't be able to open...
Read more >
md-autocomplete md-require-match workaround - CodePen
Disable caching of queries? Disable the input? By default, md-autocomplete will cache results when performing a query. After the initial call is performed, ......
Read more >
how to disable the input field after reaching 15 characters ,and ...
[Solved]-how to disable the input field after reaching 15 characters ,and also should not allow the spaces between the words using regular expression-angular.js....
Read more >
2 ways to disable chrome autocomplete on input fields - HTML ...
Your browser can't play this video. Learn more. Switch camera.
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