Bug 864 - ValueChanged event is not fired for UITextField
Summary: ValueChanged event is not fired for UITextField
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: 4.x
Hardware: Macintosh Mac OS
: --- critical
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-09-16 15:31 UTC by Adrian Grigore
Modified: 2016-10-26 18:58 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Adrian Grigore 2011-09-16 15:31:32 UTC
The event "ValueChanged" is not fired on a UITextField when a charactor is
typed (or at all). 

(the Changed event IS fired in a UITextView, so I assume it's a typo?)

Steps to reproduce the problem:
1. Add a UITextField to a form. Wire it up
2. In MonoDevelop, attach to the field's ValueChanged event.
3. Put a breakpoint / logging in the valuechanged event code
4. watch it not fire the event as you type into the field


This bug seems identic to an old bug described at https://bugzilla.novell.com/show_bug.cgi?id=596930, but even though the bug is marked at RESOLVED, I was still able to reproduce it with version 4.0.7
Comment 1 Rolf Bjarne Kvinge [MSFT] 2011-09-21 07:48:58 UTC
The problem is that the native UITextField doesn't have (the native equivalent of) a Changed event, so there is nothing MonoTouch can hook up to.

There is however a notification you can observe (for the test project in the other bug report):

NSNotificationCenter.DefaultCenter.AddObserver (UITextField.TextFieldTextDidChangeNotification, (notification) =>
{
    Console.WriteLine ("Character received! {0}", notification.Object == TextField);
});

which will enable you to listen for when the text field's text changes.
Comment 2 Jiří Zoudun 2016-09-28 08:04:42 UTC
The cleanest way to observe UITextField changes is

_textField.AddTarget((sender, e) =>
{
    // Do your stuff in here
}, UIControlEvent.EditingChanged);

You don't have to subscribe to a system-wide notification center and you don't have to unregister observer when you're destroing a text field.
Comment 3 Flavius Demian 2016-10-26 18:58:36 UTC
The suggested fix with 

_textField.AddTarget((sender, e) =>
{
    // Do your stuff in here
}, does not work for me. 

Any other suggestions?