Reputation: 1991
It's possible to hide the keyboard of a textfield, without knowing which textfield have the focus active?
For example, if i have a view with 4 textfields, and a button to hide this view, i have to do this for be sure to close all keyboards (on the click event of the button)
textfield1.blur();
textfield2.blur();
textfield3.blur();
textfield4.blur();
Or save in a global variable the reference of the textfield that is currently open, with the help of the focus/blur event.
Upvotes: 0
Views: 318
Reputation: 1181
If you don't want to create a dependency by using a somewhat outdated module you could try this:
Create a new file and call it whatever you want, I used yourview.js
for this example. Paste the following code in it:
module.exports = {
view: Ti.UI.createView({
layout: 'vertical',
backgroundColor: '#ddd',
button: Ti.UI.createButton({ title: 'blur all textfields' }),
textfields: [
Ti.UI.createTextField({ value: 'first' }),
Ti.UI.createTextField({ value: 'second' }),
Ti.UI.createTextField({ value: 'third' }),
Ti.UI.createTextField({ value: 'fourth' }),
]
}),
construct: function()
{
var self = this;
self.view.button.addEventListener('click', function(){
for(var i in self.view.textfields)
self.view.textfields[i].blur();
});
// Add textfields to view
for(var i in self.view.textfields)
self.view.add(self.view.textfields[i]);
// Add button to view
self.view.add(self.view.button);
return self.view;
}
};
The yourview.js
file contains everything you want to show in that particular view. The construct function will add everything together when you're going to use the view in your Window object which will look like this:
var win = Ti.UI.createWindow({
yourview: require('namespace/ui/yourview').construct()
});
// Add your reference to the scope of the Window object
win.add(win.yourview);
win.open();
// If you want to get the value of the textfields in this scope just use it like this:
Ti.API.info(win.yourview.textfields[0].value);
This way you have everything you want in separate files :)
Tested and works in iOS 9.3 simulator with Ti.5.4.0 SDK.
Upvotes: 1
Reputation: 194
Use a custom module like Ti.Keyboard:
https://github.com/manojdcoder/keyboard
Upvotes: 0