Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brentonhouse/2ffd923d41632d29bbd45c5516751d76 to your computer and use it in GitHub Desktop.
Save brentonhouse/2ffd923d41632d29bbd45c5516751d76 to your computer and use it in GitHub Desktop.
Hide/Show iOS keyboard w/ Appcelerator Alloy

Use the following code to hide and show the iOS keyboard and toolbar when using the keyboard toolbar buttons.

var hideKeyboard = function(e) {
var parent_name = e.source.textField;
if(parent_name) {
var parent = $[parent_name];
parent.blur();
parent.keyboardToolbar.visible = false;
}
};
var showKeyboard = function(e) {
e.source.keyboardToolbar.visible = true;
};
<Alloy>
<TextField id="myTextField" width="Ti.UI.FILL" textAlign="Titanium.UI.TEXT_ALIGNMENT_RIGHT" keyboardType="Ti.UI.KEYBOARD_TYPE_DECIMAL_PAD" verticalAlign="Ti.UI.TEXT_VERTICAL_ALIGNMENT_CENTER" onFocus="showKeyboard">
<KeyboardToolbar>
<Toolbar>
<Items>
<Button systemButton="FLEXIBLE_SPACE" />
<Button systemButton="DONE" onClick="hideKeyboard" textField="myTextField" />
</Items>
</Toolbar>
</KeyboardToolbar>
</TextField>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment