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
NSControl -rac_textSignal doesn't work when programatically setting text #765
Comments
The consistency with AppKit here is a feature, not a bug. It would be weird, IMO, for This doesn't always make sense, but generally events that propagate to the view layer should be considered "final." If you need to filter or transform them before that point, it should be done through a view model or something along those lines. What's the use case for observing programmatic changes? |
Specific example: I have a form with several text fields and a Clear button, clicking Clear sets |
In terms of MVVM, the correct design would be to perform validation upon the view model, not the view. The view model would have two-way bindings to the text fields. Then, the Clear button can reset the fields of the view model, and everything is ✨. MVC would be fairly similar, just with an intermediary view controller or model instead. |
I had considered that, but using bindings is a problem on its own in my particular case. That's irrelevant to this question, however, so I think this can be closed. Thanks! |
FWIW, even if Cocoa Bindings™ is a problem, you can use |
I know this has been closed for a long time but I found a solution for your problem @indragiek. This way your detecting whenever the text signal fires AND for programatic changes to the text property. |
@startupthekid thanks, it helps for me. |
@startupthekid thanks a ton! |
If I set text on an
NSTextField
programatically via-setStringValue:
or-setAttributedStringValue:
, this doesn't triggerNSControlTextDidChangeNotification
, which means that-rac_textSignal
won't pick up the change either. It only works when the text is being edited by user interaction.Easy fix would be to use
-rac_signalForSelector:
to intercept calls to the setters as well (in addition to registering forNSControlTextDidChangeNotification
). Any other ideas?The text was updated successfully, but these errors were encountered: