mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
component builder fixed
component builder now can handle properly empty text or text with spaces
This commit is contained in:
@ -3,6 +3,7 @@ import view = require("ui/core/view");
|
||||
import builder = require("ui/builder");
|
||||
import buttonModule = require("ui/button");
|
||||
import switchModule = require("ui/switch");
|
||||
import searchBarModule = require("ui/search-bar");
|
||||
import textFieldModule = require("ui/text-field");
|
||||
import gridLayoutModule = require("ui/layouts/grid-layout");
|
||||
import absoluteLayoutModule = require("ui/layouts/absolute-layout");
|
||||
@ -690,3 +691,17 @@ export function test_parse_NestedRepeaters() {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_searchbar_donotcrash_whentext_isempty() {
|
||||
var p = <Page>builder.parse('<Page><SearchBar text="" hint="Search" /></Page>');
|
||||
var sb = <searchBarModule.SearchBar>p.content;
|
||||
|
||||
TKUnit.assertEqual(sb.text, "");
|
||||
};
|
||||
|
||||
export function test_searchbar_donotcrash_whentext_isspace() {
|
||||
var p = <Page>builder.parse('<Page><SearchBar text=" " hint="Search" /></Page>');
|
||||
var sb = <searchBarModule.SearchBar>p.content;
|
||||
|
||||
TKUnit.assertEqual(sb.text, " ");
|
||||
};
|
@ -169,14 +169,18 @@ export function setPropertyValue(instance: view.View, instanceModule: Object, ex
|
||||
attrHandled = (<any>instance)._applyXmlAttribute(propertyName, propertyValue);
|
||||
}
|
||||
if (!attrHandled) {
|
||||
// Try to convert value to number.
|
||||
var valueAsNumber = +propertyValue;
|
||||
if (!isNaN(valueAsNumber)) {
|
||||
instance[propertyName] = valueAsNumber;
|
||||
} else if (propertyValue && (propertyValue.toLowerCase() === "true" || propertyValue.toLowerCase() === "false")) {
|
||||
instance[propertyName] = propertyValue.toLowerCase() === "true" ? true : false;
|
||||
} else {
|
||||
if (propertyValue.trim() === "") {
|
||||
instance[propertyName] = propertyValue;
|
||||
} else {
|
||||
// Try to convert value to number.
|
||||
var valueAsNumber = +propertyValue;
|
||||
if (!isNaN(valueAsNumber)) {
|
||||
instance[propertyName] = valueAsNumber;
|
||||
} else if (propertyValue && (propertyValue.toLowerCase() === "true" || propertyValue.toLowerCase() === "false")) {
|
||||
instance[propertyName] = propertyValue.toLowerCase() === "true" ? true : false;
|
||||
} else {
|
||||
instance[propertyName] = propertyValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user