2013-04-02 28 views
10

我在我的頁面中有一個對話框,其中包含一個輸入字段(日期,日曆)。問題在於打開對話框後直接打開日曆,因爲焦點是在第一個輸入上設置的。如何禁用Primefaces對話框中第一個輸入的焦點?

有沒有辦法在Primefaces中禁用焦點?

+2

你能剛Tab鍵順序設置爲不同的領域,使不同的領域已經專注打電話? –

+0

只有一個inputField :( – Johnny2012

回答

11

您可以更改默認行爲;

http://forum.primefaces.org/viewtopic.php?f=3&t=29050

你總是可以覆蓋小部件的默認行爲,例如以防止對話框打開日曆焦點;

PrimeFaces.widget.Dialog.prototype.applyFocus = function() { 
    var firstInput = this.jq.find(':not(:submit):not(:button):input:visible:enabled:first'); 
    if(!firstInput.hasClass('hasDatepicker')) { 
     firstInput.focus(); 
    } 
} 

原始碼是;

PrimeFaces.widget.Dialog.prototype.applyFocus = function() { 
    this.jq.find(':not(:submit):not(:button):input:visible:enabled:first').focus(); 
} 

如果你把你的重寫後PrimeFaces資源那麼你applyFocus的實施將有所回升,而是使用。

我建議建立像primefaces-overrides.js一個js文件,並把這樣的東西里面,有一個缺點,雖然,因爲你是對編碼低水平的API,你需要遷移過程中需要注意的迴歸,雖然我們的目標是儘可能保持向後兼容性。

+0

多個日期選擇器如何解決相同的問題?它在一個日期選擇器上工作正常@CagatayCivici –

1

另一個技巧來解決這個問題:

我加了文字輸入在我的對話框對話框的第一個輸入:

<p:dialog id="myDialogId" widgetVar="myDialog".... 

    <p:inputText id="fixForFocusProblem"/> 

    <p:calendar ... 
    .. 
</p:dialog> 

,並顯示該對話框時,我稱之爲:

$('#myForm\\:fixForFocusProblem').show(); 
myDialog.show(); 
$('#myForm\\:fixForFocusProblem').hide(); 

通過這種方式,焦點會放在立即看不到的輸入文本上。

不是很好,但它的作品沒有視覺干擾。

0

這也將做到:

<p:dialog onShow="$(document.activeElement).blur()" ...> 

或者Primefaces jQuery的

<p:dialog onShow="jQuery(document.activeElement).blur()" ...> 
0

在.xhtml添加此腳本:

PrimeFaces.widget.Dialog.prototype.applyFocus = function() { 
     var firstInput = this.jq.find(':not(:submit):not(:button):input:visible:enabled:first'); 
     if (!firstInput.hasClass('hasDatepicker')) { 
      firstInput.focus(); 
     } 
    } 
+0

這裏與接受答案中的代碼相比有什麼不同? – Kukeltje

2

簡單的東西可以設置焦點默認情況下,你有另一個輸入。

<p:dialog id="dialog" header="Users" focus="savebtn" widgetVar="txtName"> 

如果從另一個文件

<p:dialog id="dialog" header="Users" focus="savebtn" widgetVar="formRegUsers:txtName"> 
+0

也可以設置焦點到表單組件。 – unleashed

相關問題