2011-11-23 34 views
0

我有一個DynamicForm,其中放置了TextField。他們在自定義控制器的視圖中(如表單)。 當用戶在此字段中鍵入一些文本時,將顯示帶有可用(合適)文本值的ListGrid。 這個ListGrid通過DataSource fetching從服務器檢索數據。在dataArrived event我有一些邏輯,並決定發送另一個服務器請求或不,並把重點放在TextFieldSmartGWT TextField更改插入位置

form.focusInItem(item); 

奇怪的行爲發生在IE中。數據到達後,光標放在TextField的最開始處。 在Mozilla的Chrome中,數據到達後,textfield可能會失去焦點(即使聚焦後)。焦點放置在其他地方(textField和建議網格之間的某處)。我可以選中下一個控制器的視圖,然後按Shift + Tab回到TextField

不知道爲什麼會發生。調試時看不到任何奇怪的東西。 也許有人用SmartGWT文本控件遇到這樣的問題?

回答

0

發現了這種奇怪行爲的原因。

//> @method formItem.getSelectionRange() 
// For text-based items, this method returns the indices of the start/end of the current 
// selection. Returns null if the item doesn't have focus. 
// <P> 
// Notes: 
// <UL> 
// <LI>In Internet Explorer, if the item has lost focus since the selection was made, 
// only the start (current caret position) is returned. This is a limitation of Internet 
// Explorer.</LI> 
// If the item doesn't have focus always return null 
    // Natively the method we use in Moz would give us back the last selection, but the 
    // method we use in IE can't give us anything meaningful. 

來自從FormItem.js

因此,服務器返回的美國數據(dataArrived事件)的一部分後,將數據提取到ListGridTextField失去焦點。當我們手動將焦點放回文本字段(form.focusInItem(item);)時,選擇是(0,0) - 字段的開始。但只在IE中。因此,我們必須在提取數據之前保存上次選擇,然後在將焦點手動放回到文本字段後應用此選擇。 而且畢竟數據業務,並把重點和設置選擇之前,我們必須form.redraw();

1

當你發現說,這是IE瀏覽器的原生限制的意見。但是,如果通過fetchData()的dsRequest屬性參數傳遞rpcRequest.showPrompt:false,則可以避免焦點離開字段。

此外,重點應該已經恢復到文本字段完成後,我們有自動化測試顯示這種情況。如果您發現這種情況不會發生,請隨時提交一個測試用例 - 但如果確實如此,請確保提及您的GWT和SmartGWT版本以及涉及的任何第三方庫。