TextField and set a placeholder textshowTitleLabel() 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.
Simple: Move the (not a good idea)placeholderText setter line to the didSet of the placeholder
I will submit a PR ASAP
Good catch. I will add this to the release later today. Thank you!
As always, I appreciate you bringing this to our attention. It is now fixed in 1.39.13 :)
Sorry, I didn't see that you would submit a PR.
Thanks and No problem
I had fixed it in my PR but I didn't got the time to actually test it, therefore, No PR from me.
Thanks again
Glad to be of any help
M.
Sorry to bother you again,
This fix doesn't work. When I was working on it yesterday, I did the same thing (at first) and forgot to consider this fact that showTitleLabel() actually sets the placeholder to nil after storing it in placeholderText therefore in the didSet we will lose the placeholder value altogether! The only way I could think of (without introducing a new state variable) is to check if the titleLabel is visible when updating the placeholderText. i.e.:
if let v: String = placeholder {
attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
}
if !titleLabel.hidden {
placeholderText = placeholder
}
The idea here is that the problem happens only when the title label is visible, the rest is working just fine.
To think about it, the whole mechanism needs to be redesigned.
Well, that won't work either! in the showTitleLabel() the titleLabel is still hidden.
In the original fix I went with your recommendation. I think that a rethink in some aspect of the TextField would be a good idea. Tomorrow I can work on it as I continue my work on the TextView. Either way there will be a fix, but I don't want to push one tonight and then not be around for the next 12 hours. If you can think of an approach that would be great too.
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
Hello folks,
I am using this since the beginning and i am facing the same issue my side too. Let me know once you can fix that as i am stuck on this change.
Quick change is highly appreciated.
Thank you in advance.
I also hit this issue.
As a quick workaround I just wrapped the setting of placeHolderText inside the didSet for placeholder in a nil check so it wouldn't overwrite. (~line 380 in TextField.swift)
if nil == placeholderText {
placeholderText = placeholder
}
It works but fails when you want to remove the placeholder.
Yeah - true. Certainly not a robust solution but works for my small use as a workaround.
Yeah, definitely works. Should revise the whole mechanism.
I'll be posting a solution later today with a couple of other issues fixed :)
I was thinking about it today. The only thing I could come up with was to introduce a new public variable that holds on to the placeholder value, propagates the changes to the underlying mechanism and acts a, well placeholder for placeholder!
It has the caveat of introducing a small redundancy and breaking the UiTextField api.
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.
Hey Man,
Let me know if you have committed the patch so that i can work on that new patch.
Thanks.
@riteshtechno Yes, almost done. Will be out later today. Thank you! :)
@riteshtechno and for those who are monitoring this issue. I am testing the solution I would like to push. Should be done momentarily.
Hey guys, please try 1.39.14. Thank you!
Thanks @danieldahan,
I can confirm it solves the problem.
I think its even worse. Now the place holder color gets changed in default place and nothing seems to be working.
@riteshtechno
Lets focus on the issue. If the placeholder color is not working right, open a new issue.
@riteshtechno The color issue is a new issue, and in general that would be a simple fix. If you open an issue with an example where it is breaking, or a suggested PR with the updated code from 1.39.14, we can release a new update.