Skip to content
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

fix(ios) : Convert property ‘value’ to string inside hasText function #10521

Merged
merged 9 commits into from
Dec 19, 2018
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITextWidgetProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (NSNumber *)hasText:(id)unused
YES);
return [NSNumber numberWithBool:viewHasText];
} else {
NSString *value = [self valueForKey:@"value"];
NSString *value = [TiUtils stringValue:[self valueForKey:@"value"]];
BOOL viewHasText = value != nil && [value length] > 0;
return [NSNumber numberWithBool:viewHasText];
}
Expand Down
48 changes: 48 additions & 0 deletions tests/Resources/ti.ui.textfield.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti, Titanium */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.UI.TextField', function () {
var win;

afterEach(function () {
if (win) {
win.close();
}
win = null;
});

it.ios('hasText', function (finish) {
win = Ti.UI.createWindow();
var textFieldA = Ti.UI.createTextField({
top: '60dip',
value: 0
});

win.add(textFieldA);

var textFieldB = Ti.UI.createTextField({
top: '120dip',
value: 0
});

win.add(textFieldB);

textFieldA.addEventListener('change', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the change event listener for? How will it be triggered in a unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When value get set , at that time also 'change' event listener get called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event will only be triggered by user input, not when changing the text programmatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case when we set number, 'change' event listener is getting called. I guess you are correct, ideally it should not call if it set programatically.
Though I have updated unit test, I'll create a ticket to check the behaviour of 'change' event listener.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For verifying the conversion of 0 to "0" -
There is no getter method implemented in this to get value from textfield. Whenever we call getter it will simply fetch value from proxy (default getter). So with getter it will always give the same value, which is number. Other places also I can see default getter (value from proxy) returned.

should(textFieldA.hasText()).be.true;
should(textFieldB.hasText()).be.true;
finish();
});

win.open();
});

});