TextBox

API Reference: UI.TextBox

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

TypeScript code blocks include examples of how to implement, override and components within the theme. You can create page with the UI Editor to make your page compatible with theming and then you can implement themable components programmatically. Once the page is created with the UI Editor, it generates a class under scripts/generated/pages. You can then extend that class with the following TypeScript classes.

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.

TypeScript
JavaScript
TypeScript
import PageSampleDesign from 'generated/pages/pageSample';
import FlexLayout = require('sf-core/ui/flexlayout');
import Application = require('sf-core/application');
import TextBox = require('sf-core/ui/textbox');
import Color = require('sf-core/ui/color');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myTextBox: TextBox;
constructor() {
super();
// Overrides super.onShow method
this.onShow = onShow.bind(this, this.onShow.bind(this));
// Overrides super.onLoad method
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
}
}
/**
* @event onShow
* This event is called when a page appears on the screen (everytime).
* @param {function} superOnShow super onShow function
* @param {Object} parameters passed from Router.go function
*/
function onShow(superOnShow: () => void) {
const { headerBar } = this;
superOnShow();
Application.statusBar.visible = false;
headerBar.visible = false;
}
/**
* @event onLoad
* This event is called once when page is created.
* @param {function} superOnLoad super onLoad function
*/
function onLoad(superOnLoad: () => void) {
superOnLoad();
this.myTextBox = new TextBox({
text: "TextBox"
});
this.layout.addChild(this.myTextBox, "myTextBox", ".sf-textBox", {
height: 100,
width: 200,
backgroundColor: 'rgba(116, 120, 246, 0.81)',
borderWidth: 1,
borderColor: "#000000",
});
}
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;