Issue
The textfield change event listener in 2.1.4 is fired differently from 3.0.0.GA SDK.
Steps to Reproduce
Run the sample below:
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
win.open();
var view = Ti.UI.createView({
backgroundColor : 'red',
top : 20,
left : 20,
height : 400,
width : 300,
layout: 'vertical'
});
win.add(view);
var textfield = Ti.UI.createTextField({
left: 20,
right: 20,
height: 40,
//maxLength: 6,
borderColor: 'black',
borderWidth: 2,
value: 'Hello'
});
view.add(textfield);
var countChangeEvents = 0;
textfield.addEventListener('change', function(_evt){
countChangeEvents++;
Ti.API.info('change event fired: ' + countChangeEvents);
var value = _evt.source.value;
if (value == 'HelloA'){
Ti.API.info('replace');
textfield.value = value.replace('Hello', '*****');
}
});
2. Enter the letter "A" at the end of the text in the textfield.
3. Notice the characters before A turn to "*".
4. If you look at the logs the API info statements show 2 change events fired for the above steps in 3.0.0.GA while in 2.1.4.GA, 3 events were fired.
Is this an intentional behavior?
Tested with: Titanium Studio, build: 3.0.3.201302201202 Titanium SDK, build: 3.1.0.v20130312161655 Device: Nexus7 Android version: 4.2 Test steps: 1. Ran App and added "A" in the end of the text console output is: I/TiAPI(2913): change event fired: 1 I/TiAPI(2913): replace W/IInputConnectionWrapper(2913): endBatchEdit on inactive InputConnection 2. Each click on the keyboard's key fires event I/TiAPI(2913): change event fired: 2 I/TiAPI(2913): change event fired: 3 I/TiAPI(2913): change event fired: 4 I/TiAPI(2913): change event fired: 5 Identical result for 3.0.2.GA
PR: https://github.com/appcelerator/titanium_mobile/pull/4072 For FR: 1. Run the above test case. 2. Add "A" at the end of the text. Check the log, it should fire three "change" events (before the fix, it only fired one "change" event). 3. Uncomment Line 22 in the above test case {quote}maxLength: 6{quote} and then run the test case again. 4. Input more characters in the text field. It should not crash (before the fix, it crashed on 4.x devices if the total characters > 6). Check the log, the "change" event should be fired when the shown text is changed. 5. Please also follow the test instruction in TIMOB-5810.
3_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/4193
Tested with: SDK:3.1.1.v20130503173050 Appcelerator Studio: 3.1.1.201305031846 OS: OSX 10.7.5 Device: Google nexus7(v 4.1) Logs change event successfully every time a character is added or deleted from textfield.