我在Cordova的SAPUI5 Web應用程序中的輸入字段上有「focus()」問題。.focus()和本機鍵盤未激活
這是我使用的代碼。
sap.ui.getCore().byId("inputQuant").focus()
我甚至嘗試以下
setTimeout(function() { sap.ui.getCore().byId("inputQuant").focus() },3000);
和
jQuery.sap.delayedCall(0, this, function() {
sap.ui.getCore().byId("inputQuant").focus();});
,但原生的Android鍵盤不是 「卡」。輸入的重點是JQuery標準,但不是來自設備的觀點。
有沒有辦法來操縱這個?
我想要做的是:從現有的屏幕上,我調用一個函數來打開一個對話框。對話框打開後,我應該關注輸入字段並彈出設備的鍵盤。
這裏是我創建對話框:
function getInputDialog(objParameters){
title = objParameters.title;
description = objParameters.description;
contentText = objParameters.contentText;
to = objParameters.to;
context = objParameters.context;
model = objParameters.model;
value = objParameters.value;
var app = sap.ui.getCore().byId("App--app");
var myDialog = sap.ui.getCore().byId('inputDialog');
if(myDialog == undefined){
var xml = '' +
'<Dialog id="inputDialog" xmlns="sap.m" title="{inputDialogModel>/title}"> ' +
' <content> ' +
' <FlexBox alignItems="Center" justifyContent="Center"> ' +
' <Label text="{inputDialogModel>/contentText}" /> ' +
' </FlexBox> ' +
' <FlexBox alignItems="Center" justifyContent="Center"> ' +
' <Input id="inputQuant" type="Number" width="100%" ' +
' description="{inputDialogModel>/description}" value="1"/> ' +
' </FlexBox> ' +
' </content> ' +
' <buttons> ' +
' <Button text="{inputDialogModel>/actionText2}" press="closeDialog2"/> ' +
' <Button text="{inputDialogModel>/actionText1}" press="closeDialog1"/> ' +
' </buttons> ' +
'</Dialog> ';
// create some dummy JSON data and create a Model from it
var data = {
title: title, //"Introduceti o cantitate",
description: description, //"buc",
contentText: contentText, //"Some Fragment Content",
actionText1: "Confirma",
actionValue1: to, //
actionText2: "Renunta",
model: model
};
// create a dummy Controller for the action in the Dialog
var oDummyController = {
onAfterRendering: function(){
setTimeout(function() { sap.ui.getCore().byId("inputQuant").focus() },2000);
jQuery.sap.delayedCall(0, this, function() {
sap.ui.getCore().byId("inputQuant").focus();});
},
onBeforeShow: function(){
setTimeout(function() { sap.ui.getCore().byId("inputQuant").focus() },2000);
jQuery.sap.delayedCall(0, this, function() {
sap.ui.getCore().byId("inputQuant").focus();});
},
closeDialog2: function(){
myDialog.close();
},
closeDialog1: function(){
//Update model with new value for quant
context.getModel(model).updateBindings();
myDialog.close();
app.to(to);
} else {
var oModeli18n = new sap.ui.model.resource.ResourceModel({
bundleUrl: "i18n/i18n.properties"
});
sap.m.MessageToast.show(oModeli18n.getProperty("Pop_up_add_quantity"));
}
}
};
// instantiate the Fragment if not done yet
myDialog = sap.ui.xmlfragment({fragmentContent:xml}, oDummyController);
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(data);
myDialog.setModel(oModel, "inputDialogModel");
}
sap.ui.getCore().byId("inputQuant").setValue(value);
sap.ui.getCore().byId("inputQuant").focus();
return myDialog;
}
如果我手動按下輸入,我看到鍵盤,但是當我使用的編碼,它不會觸發。
在此先感謝您, Nep。
我試過上面的代碼在一個現有的和普通的視圖。 – Nepriceputu
在: onBeforeShow onAfterRendering 頁面的功能。 Ergo我想我的代碼可能有問題。我爲什麼這麼說,因爲當我在XML片段的這兩個函數之一中添加一個斷點時,它不會停止。有任何想法嗎 ? – Nepriceputu