2014-10-27 115 views
0

我是新來CakePHP的,我在CakePHP的

$ajax->submit( 'Submit', array( "update" => "gridbox_script", "url" => '/flots/comparaison_gridbox_update', "div"=>"button_submit", "loading" => "setIboxOpacity = setOpacity;showBG();showIndicator();" , "complete" => "hideBG();hideIndicator()" ) );

提交按鈕,我想補充一個JavaScript驗證,如果驗證返回true,則它應該繼續提交,否則提交應該被終止。

整個提交通過ajax調用,我建議使用$ajax來實現。

我的javascript功能:

var firstCompare = new Array(); 
fucntion myValidation(){  
var otherCompare = new Array(); 
if(document.getElementById("file1").checked) 
otherCompare.push('file1'); 
result = (otherCompare.length === _.intersection(otherCompare, firstCompare).length); 
firstCompare = otherCompare; 
return result; 
} 

請幫助我。

回答

0

使用該標識並檢查按鈕的提交或單擊事件。

$(document).ready(function() { 
    $('#formId').on('submit', function() { 
     var val = your_function() //call the function and store the return value 
     if (val) { 
      //do the submission 
     } else { 
      //code in case of false 
     } 
    }); 
}); 
+0

我可以在cakePHP'$ ajax-> submit'中添加javascript函數嗎? – user2660409 2014-10-27 10:22:21

+0

你正在使用哪個版本的蛋糕?我認爲它小於2.x.你可以在js文件中寫入函數並根據需要使用它。 – 2014-10-27 10:25:52