-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MdInput - Placeholder does not float when using formControl setValue() #2441
Comments
…ically with reactive forms Fixes the input placeholder not being floating when the value is updated programmatically via `FormControl.setValue`. This was because the listener that handles the value changes gets initialized before the `FormControl`. Fixes angular#2441.
…ically with reactive forms Fixes the input placeholder not being floating when the value is updated programmatically via `FormControl.setValue`. This was because the listener that handles the value changes gets initialized before the `FormControl`. Fixes angular#2441.
Ha! I just came across this bug too! |
In the meantime, if you are only experiencing this because the initial setting of the values is async then you could provide "dummy values" to the form controls when you create them, so that the input directive thinks that they are not empty before the |
…ically with reactive forms Fixes the input placeholder not being floating when the value is updated programmatically via `FormControl.setValue`. This was because the listener that handles the value changes gets initialized before the `FormControl`. Fixes angular#2441.
Right now the MdInputDirective tries to cache the `value` of the input. > For this the MdInputDirective needs to listen for NgControl value :changes and for native `(change)` events. This caching will be problematic when a value is set directly to the input element (using `[value]` property binding) because Angular is only able to recognize this change in the first ChangeDetection. > The solution of updating the value in the `ngAfterViewInit` lifecycle hook, will result in a binding change (`[class.md-empty]` in the view) while being in a ChangeDetection, which leads to a ChangeDetection error. Fixes angular#2441. Fixes angular#2363
Right now the `MdInputDirective` tries to cache the `value` of the input. To do this, the `MdInputDirective` needs to listen for `NgControl` value changes and for native `(change)` events. This will be problematic when a value is set directly to the input element (using `[value]` property binding) because Angular is only able to recognize this change in the first ChangeDetection. ```html <md-input-container> <input md-input [value]="myValue" placeholder="Label"> </md-input-container> ``` The approach of updating the value in the `ngAfterViewInit` lifecycle hook, will result in a binding change while being in a ChangeDetection, which leads to a ChangeDetection error. ``` Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'. ``` Fixes angular#2441. Fixes angular#2363
Right now the `MdInputDirective` tries to cache the `value` of the input. To do this, the `MdInputDirective` needs to listen for `NgControl` value changes and for native `(change)` events. This will be problematic when a value is set directly to the input element (using `[value]` property binding) because Angular is only able to recognize this change in the first ChangeDetection. ```html <md-input-container> <input md-input [value]="myValue" placeholder="Label"> </md-input-container> ``` The approach of updating the value in the `ngAfterViewInit` lifecycle hook, will result in a binding change while being in a ChangeDetection, which leads to a ChangeDetection error. ``` Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'. ``` Fixes angular#2441. Fixes angular#2363
@brunopereira27 is your plunkr working ? Because I was trying to see your issue but I have that : So I don't see any problem. I'm having (probably) the same problem : But as your Plunkr seems to be working I'm not sure. I'm using reactive form and |
Hi .. this still an issue in beta.10.. shouldnt be open? Thanks @petebacondarwin , the workaround works! I used just a space in the string and now it loads with the initial value and correct placeholder
|
Should definitely be reopen ;) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
Placeholder should be floating over input when setting the input value using setValue of its formControl.
What is the current behavior?
When I use setValue, the input contains the value set and the placeholder overlays the value, without floating over it. If I enter a text manually just after using setValue, the placeholder goes to the right place.
What are the steps to reproduce?
Here's a plunker that reproduces the issue:
http://plnkr.co/edit/huUsxFmbFKSZuCG92EmQ?p=preview
Which versions of Angular, Material, OS, browsers are affected?
Angular: 2.3.1
material: git+https://github.com/angular/material2-builds.git but also tested on 2.0.0-beta1
Browser: Chromium 55.0.2883.87
Os: Chromium 55.0.2883.87
The text was updated successfully, but these errors were encountered: