Hi,
I have a Ext.Msg.show dialog that appears for a user to create a new folder or rename a folder within a folder tree. I would like it if on load of the dialog window, the textbox was in focus so that the user could immediately start typing a new name without having to click on it but I cant seem to get it to work in IE or firefox. the normal select() or focus() methods dont work. I have tried:
var name = document.getElementById("newName");
setTimeout("name.focus();", 0);
name.focus();
name.select();
However none of those seem to work. Any suggestions?:s
The show method is an asynchronous operation; that is the code immediately following it will likely execute before the messagebox has been created and rendered. It does have the ability to accept a callback function via the 'fn' config option though, and this would be the appropriate place to put your focus code. See the API docs for Ext.MessageBox.show() for more details.
And in the future please use code tags when posting code, it is very hard to read code without formatting.
This is my dialog box. the id of the variable textToShow is "newName".
Ext.Msg.show({
cls: 'dialog-border',
closable: false,
focus:true,
title: Mistic.constants.newFolderMessages.TITLE,
msg: Mistic.constants.newFolderMessages.MESSAGE_BEGIN +
textToShow +Mistic.constants.newFolderMessages.MESSAGE_END +
Mistic.constants.textBoxes.WRITE_SIZE_35+
Mistic.constants.textBoxes.CLOSE_TAG,
buttons: Ext.Msg.OKCANCEL, how to set focus on a field in a dialog? - Ext JS Forums:: 10 posts - Last post: Dec 12, 2007Send a private message to bwang_dal · Find all posts by bwang_dal . dialog.on ('show', function() { Ext.fly('myTextBox').focus(); }); http://extjs.com/forum/showthread.php?p=98263HOME |
width: 375,
value: valueText,
fn: function(button) {
var folderName = document.getElementById("newName").value;
if (button == Mistic.constants.buttonLabels.EXT_TEST_OK){
if(folderName == Mistic.constants.messages.BLANK_STRING) {
Mistic.events.alertMessage({
title: Mistic.constants.newFolderMessages.MESSAGE_NO_NAME _ENTERED_TITLE,
msg: Mistic.constants.newFolderMessages.MESSAGE_NO_NAME _ENTERED_CONTENT,
fn: function(button){
if(button == Mistic.constants.buttonLabels.EXT_TEST_OK){
newNameMessage(valueText, parentNode, textToShow);
}
}
});
}
else if(folderName.length > 50) {
Ext.Msg.alert(Mistic.constants.newFolderMessages.M ESSAGE_50_CHARACTERS_TITLE,
Mistic.constants.newFolderMessages.MESSAGE_50_CHAR ACTERS);
createNewItem(obj, ee, folderName);
}
else {
var myNode = parentNode;
var myReader = new Ext.data.JsonReader({},
Ext.data.Record.create());
var addAjax = Mistic.ux.Ajax.request({
url: Mistic.appUrl +
Mistic.constants.newFolderMessages.URL_NEW_FOLDER_ ACTION,
params:
{
parentId: parentNode.id,
folderName: Mistic.mainWin.Mistic.events.replaceChars(folderNa me),
folderType: (parentNode.attributes.folderType ?
parentNode.attributes.folderType : 'MAIL')
},
success:function(ajax, response){
Mistic.mainWin.Mistic.mua.refreshFolderManagerTree ()
},
failMessage: Mistic.constants.messages.ERROR_ADD
});
myNode.customExpand = true;
myNode.parentNode.expanded = true;
}
}
}
});
document.getElementById("newName").focus();
I call the code after the creation of the Ext.Msg.show.
When are you calling this code in relation to when the dialog is shown?
Nortel Unveils Vision, Strategy for Israeli High-Performance Net
Busy Friday Leads to Strong Close for Net Stocks
|