2013-04-05 25 views
0

我在JSF ajax請求和jQuery事件中遇到問題。jsf ajax在jQuery驗證功能後觸發

我使用jQuery事件來驗證組成部分是這樣的:

jQuery(".btnNextStep").live("click", function(e) { 
    var error = !validate(id); 
      ... 
    return error; 

和相同的按鈕下,我有一個Ajax事件:

<h:commandButton type="button" value="Etape suivante" class="btn btn-large btn-primary btnNextStep" id="btnFormIdentite"> 
<f:ajax execute="identite" render="@none" /> 
</h:commandButton> 

的問題是,AJAX請求是submited即使jQuery事件返回false!

我可怎麼辦,這樣的要求是jQuery驗證功能後發送?

我已經試過的onEvent上f:ajax但似乎這不是可以調用jQuery的命名空間內的函數:

(jQuery(document).ready(function() {...) 

我希望你明白我的問題。 謝謝。

+1

使用服務器端驗證。 – 757071 2013-04-05 09:15:51

+0

另請參見:http://stackoverflow.com/questions/8416695/jsf-ajax-request-is-not-fired-when-combined-with-js-client-side-validation – 757071 2013-04-05 09:17:47

回答

0

嘗試這樣定義您的驗證功能:

​​

而上點擊使用:

<h:commandButton type="button" value="Etape suivante" class="btn btn-large btn-primary btnNextStep" id="btnFormIdentite" onClick="return vlidateNextStep();"> 
    <f:ajax execute="identite" render="@none" /> 
</h:commandButton> 
+0

感謝您的答覆。我已經嘗試過,但函數vlidateNextStep需要在jquery名稱空間之外。 – user1823099 2013-04-05 09:21:09

+0

驗證是在jquery命名空間裏面... – user1823099 2013-04-05 09:21:41

+0

@ user1823099試試在一個函數裏面的documentReady中創建你需要的部分並將它調用到外部documentReady – 2013-04-05 09:39:18