When i opened the window, the keyboard will come(text field automatically focused).I don't want the keyboard pop up, when a window open in android and iphone.Only want when the textfield or text area will focus.I give the textfield.blur () ,but it didn't work.Please help to solve this problem.
5 Answers
hello , You can Hide your textfield at the Time of creation And show it in open event of window by setting Timeout function.
win.addEventListener('open', function(e) {
setTimeout(function(e){
txtMedicineName.show();
},1000) ;
});
Hi Dinesh
There is nothing in the code you provided to make the keyboard automatically display. Keyboards do not automatically appear just because there is Text Field on the screen. You would have to either set the focus to the specific text field or the user would need to interact with the text field directly.
I can only assume that you have a problem somewhere else as the code below (yours) is fine.
var medicineName = 'example'; // added just so example works var txtMedicineName = Titanium.UI.createTextField({ value : medicineName, top : '15dp', paddingLeft : '10dp', paddingRight : '10dp', color : '#000000', backgroundImage : '/images/text-field.png', backgroundColor : 'transparent', left : '15dp', font : { fontFamily : 'Arial', fontSize : '12sp' }, width : '291dp', height : '35dp' }); txtMedicineName.blur(); medicationModifyWin.addEventListener('open', function() { txtMedicineName.blur(); }); viewMedicationModifyBody.add(txtMedicineName);BTW none of this is required.
txtMedicineName.blur(); medicationModifyWin.addEventListener('open', function() { txtMedicineName.blur(); });The answer provided by Moiz does not address the actual problem, there is no need to try hiding the text field first - you need to find the reason why the focus is being called.
Please provide the code for the view viewMedicationModifyBody just in case there is something going on there. Also do a check for any code with focus() mentioned which you may have in your code by accident.
When adding code check out the 3 ~ syntax to help show your code more clearly the links option on the top of the answer box you type in explains how.
Please provide the code you use to create the textfield and any other references you have to it, without code people can only guess as to what may be wrong.
Help us to help you.
var txtMedicineName = Titanium.UI.createTextField({ value : medicineName, top : '15dp', paddingLeft : '10dp', paddingRight : '10dp', color : '#000000', backgroundImage : '/images/text-field.png', backgroundColor : 'transparent', left : '15dp', font : { fontFamily : 'Arial', fontSize : '12sp' }, width : '291dp', height : '35dp' }); txtMedicineName.blur(); medicationModifyWin.addEventListener('open', function(){ txtMedicineName.blur(); });
viewMedicationModifyBody.add(txtMedicineName);
here,i created a textfield and add to the view(viewMedicationModifyBody) and the view is in the window. when the window is open, textfield will focus and pop up the keyboard.The blur() didn't work.
Hello , every body , finally i got the solution of this crazy problems ,
like moiz said , i used :
win.addEventListener('open', function(e) {
setTimeout(function(e){
txtMedicineName.show();
},1000) ; });
but in place of using hide and show , i used edite attribute or method .
For exemple , if you have textfield , you have to do like this :
var email_field = Titanium.UI.createTextField({ value:'', color:'#336699', height:43, width:'70%', right:72, font:{ fontSize:14, fontWeight:'bold' }, bottom:15 }); email_field.editable = false;
after , in the end of the page , add this :
win.addEventListener('open', function(e) {
setTimeout(function(e){
email_field.editable = true;
},1000) ;
});
Otherwise , if you have text area , you have to use the method :
var textArea = Titanium.UI.createTextArea({ value:'', height:80, width:20, top: 70, left : 10, font:{ fontSize:14, fontWeight:'bold'}, color:'#ccc', textAlign:'left', keyboardType:Titanium.UI.KEYBOARD_DEFAULT, borderColor:'#ccc', borderWidth:0, softKeyboardOnFocus: Titanium.UI.Android.SOFT_KEYBOARD_DEFAULT_ON_FOCUS });
myview.add(textArea);
textArea.setEditable(false);
In the end of the page , add this :
win.addEventListener('open', function(e) {
setTimeout(function(e){
textArea.setEditable(true);
},1000) ;
});
Driss make everybody happy :) !
Your Answer
Think you can help? Login to answer this question!