2013-06-04 56 views
1

我有一個表單和一個必填字段,如下所示。 如果必填字段爲空,我添加了aui字段驗證器以防止表單提交。 但它不工作。 有人請幫助我。如何防止aui-form提交,當aui要求提交驗證器爲空時

<aui:form id="fm" name="fm" method="post" action="<%= someURL %>"> 
    <aui:input id="txtArea" label="value" name="preferences--txtArea--" type="textarea" style="width:330px;height:65px;" > 
     <aui:validator name="required" /> 
    </aui:input> 
    <aui:input name="termsAndCondition" id="termsAndCondition" type="checkbox" label="termsAndConditons"/> <br> 
    <aui:button type="button" value="save" onClick="showDialog()" /> 
</aui:form> 

<aui:script> 
function showDialog() 
{ 
    var termsAndCondition= A.one('#<portlet:namespace/>termsAndCondition').attr('value'); 
    var r=confirm("Are you sure to change data?"); 
    if (r==true && termsAndCondition=="true") 
    { 
     A.one('#<portlet:namespace/>fm').submit(); 
    } 
} 
</aui:script> 

回答

0

我發現錯在我的代碼.. 我用按鈕類型=「按鈕」,你可以看到

<aui:button type="button" value="save" onClick="showDialog()" /> 

但對於使用根據要求AUI實地驗證工作,提交表單時所需的字段是爲了防止空。使用按鈕類型=「提交」。如此校正線

<aui:button type="submit" value="save" onClick="showDialog()" /> 

現在,它的做工精細:) :)

0

嘗試用這種方法

<aui:form id="fm" name="fm" method="post" action="<%= someURL %>" onSubmit="check();> 


<script type="text/javascript"> 

    function check() 
    { 
    } 
</script> 

OR

可以功能的ShowDialog()

希望返回false這將幫助你

+0

可以請你告訴我怎麼在功能檢查(),或在條件返回false從我的函數的ShowDialog()查詢。 – user2341971

+0

只是保持檢查功能,因爲它是..嘗試它 –

+0

我試過了,但它不工作。 – user2341971