Material: Wrong TextField Placeholder text (and titleLabel text) after changing Placeholder + Refocus focus

Steps to reproduce:

  1. Setup a TextField and set a placeholder text
  2. Start typing
  3. (While still focused) Clear the text field programmatically and change the placeholder string (Placeholder will be right at this point)
  4. Focus on the text field
  5. Leave the text field (at this point the placeholder string will get back to the original value)

Reason:

showTitleLabel() uses a variable called placeholderText to store the placeholder string before removing it from the text field. hideTitleLabel() uses the same variable to restore the placeholder string. Now if the placeholder value gets updated while the title label is displaying (between a call to the mentioned methods), the placeholderText variable doesn’t get updated, and when hideTitleLabel() gets called, it will set the placeholder value back to the the last time showTitleLabel() has updated it.

Resolution:

Simple: Move the placeholderText setter line to the didSet of the placeholder (not a good idea)


I will submit a PR ASAP

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 24 (19 by maintainers)

Most upvoted comments

Hey guys, please try 1.39.14. Thank you!

I’ll have a better idea of my solution in a couple hours when I am in front of my computer. All the suggestions though are good, as they are pointing out edge cases that still exist. I’ll probably rework the internals to handle this more appropriately than introduce a quick fix.

I’ll be posting a solution later today with a couple of other issues fixed 😃

Yeah, my original idea sucked. That’s why I didn’t submit a PR at the first place. I’m working today and I will find the time to do some thinking and I will share my ideas later on. a bientôt