components icon indicating copy to clipboard operation
components copied to clipboard

MdInput - Placeholder does not float when using formControl setValue()

Open brunopeartree opened this issue 9 years ago • 6 comments

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

brunopeartree avatar Dec 28 '16 09:12 brunopeartree

Ha! I just came across this bug too!

petebacondarwin avatar Dec 28 '16 19:12 petebacondarwin

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 setValue finally fills them.

petebacondarwin avatar Dec 28 '16 19:12 petebacondarwin

@brunopereira27 is your plunkr working ? Because I was trying to see your issue but I have that : image

So I don't see any problem.

I'm having (probably) the same problem : image

But as your Plunkr seems to be working I'm not sure.

I'm using reactive form and patchValue tho.

maxime1992 avatar Jan 19 '17 15:01 maxime1992

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

city: [' ', [<any>Validators.required, <any>Validators.minLength(5)]],

https://github.com/angular/material2/issues/2613#issuecomment-325980984

mariohmol avatar Aug 30 '17 12:08 mariohmol

Should definitely be reopen ;)

maxime1992 avatar Aug 30 '17 13:08 maxime1992

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.