This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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)

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


Attachments

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 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?

Note You need to log in before you can comment on or make changes to this bug.