TextBox

API Reference: UI.TextBox

TextBox is a UI object, contents of which is editable by the user.

Handling Keyboard Events on Page Transitions

For Android, the keyboard might not be closed on page transitions. To prevent this behavior, you should call removeFocus() from any textbox before changing the page.

JavaScript
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const Color = require('sf-core/ui/color');
const FlexLayout = require('sf-core/ui/flexlayout');
const TextBox = require('sf-core/ui/textbox');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
}
});
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
var myTextBox = new TextBox({
height:100,
width:200,
backgroundColor:Color.create("#5500A1F1"),
text: "TextBox",
borderWidth: 1
});
this.layout.addChild(myTextBox);
}
);
module.exports = Page1;

TextBox inputView

The custom input view to display instead of system keyboard when the textbox object became focus. This property works only for iOS only.

JavaScript
JavaScript
const FlexLayout = require("sf-core/ui/flexlayout");
const TextAlignment = require("sf-core/ui/textalignment");
const TextBox = require("sf-core/ui/textbox");
const Color = require("sf-core/ui/color");
const View = require("sf-core/ui/view");
const Application = require("sf-core/application");
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const Button = require('sf-core/ui/button');
const Label = require('sf-core/ui/label');
const Picker = require("sf-core/ui/picker");
const items = [ //Text values of the picker
"item 1",
"item 2",
"item 3",
"item 4",
"item 5"
];
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
}
});
const myPicker = new Picker({
items: items,
currentIndex: 0
});
myPicker.onSelected =function(index){
myTextBox.text = items[index]
}
var myTextBox = new TextBox({
height: 100,
width: 200,
backgroundColor: Color.create("#5500A1F1"),
text: "TextBox",
borderWidth: 1,
textAlignment: TextAlignment.MIDCENTER,
alignSelf:FlexLayout.AlignSelf.CENTER
});
myTextBox.ios.inputView = {
height: 300,
view: myPicker
};
this.layout.addChild(myTextBox);
}
);
module.exports = Page1;