2015-05-04 31 views
0

我正在開發使用Onsen-UI的Cordova應用程序。在一個頁面中,我使用包含表單元素的ons-dialog顯示一個對話框。我已經使用AngularJS指令ng-show實現了驗證。驗證AngularJS的錯誤消息未顯示在ONSEN-UI的Ons-Dialog頁面中

單擊提交按鈕後,錯誤消息不會顯示在對話框頁面中,但正在進行驗證。應用程序的其他頁面完全顯示所有錯誤消息,但ons-dialog不顯示該錯誤消息。

我的代碼:

<ons-template id="info.html"> 
<ons-dialog var="myDialog" animation="fade" cancelable> 

    <ons-toolbar inline fixed-style> 
     <div class="center"> 
      Info 
     </div> 
    </ons-toolbar> 
    <form name="myForm" ng-submit="submitted=true; myForm.$valid && myDialog.hide();" novalidate> 

     <div style="text-align:center;margin:0px 10px 0px 10px"> 

      <input name="rFName" ng-model="rFName" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="First Name" required> 
      <div style="color:red;font-size:13px;text-align:center"> 
       <span ng-show="submitted && myForm.rFName.$error.required">*required</span> 

      </div> 

      <input name="rLName" ng-model="rLName" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="Last Name" required> 
      <div style="color:red;font-size:13px;text-align:center"> 
       <span ng-show="submitted && myForm.rLName.$error.required">*required</span> 

      </div> 

      <input type="email" name="rEmail" ng-model="rEmail" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="Email" required> 
      <div style="color:red;font-size:13px;text-align:center"> 
       <span ng-show="submitted && myForm.rEmail.$error.required">*required</span> 
       <span ng-show="submitted && myForm.rEmail.$error.email">*Invalid email</span> 
      </div> 

      <input type="number" name="rPhone" ng-model="rPhone" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="Contact Number" required> 
      <div style="color:red;font-size:13px;text-align:center"> 
       <span ng-show="submitted && myForm.rPhone.$error.required">*required</span> 
       <span ng-show="submitted && myForm.rPhone.$error.number">*Please enter valid phone number</span> 
      </div> 

     </div> 


     <p></p> 


     <div style="text-align:center" ng-controller="myCtrl"> 
      <ons-button style="width:35%;background:#B54747" ng-click="submitted=true; myForm.$valid && myDialog.hide();">Save</ons-button> 
      <ons-button id="cancel_btn" style="width:35%;background:#B54747" ng-click="myDialog.hide();">Cancel</ons-button> 
     </div> 

    </form> 
    <p> 

    </p> 




</ons-dialog> 
</ons-template> 
+0

請,也控制代碼 –

+0

提供其實沒有什麼有趣的控制器代碼。我已經對它進行了重新評估。此處的問題與Ons-Dialog元素中的驗證有關。實際上,如果我們在頁面中輸入正確的詳細信息,提交將隱藏執行驗證的對話框。但是如果我們不輸入所需的細節,AngularJS的錯誤消息不會顯示。這是問題。 –

回答

2

只是地方上的表單元素或形式元素的父不僅包含保存和取消按鈕,因爲表單字段和表單按鈕是兩個不同的範疇div標籤NG-控制器。

<form name="myForm" ng-controller="myCtrl" ng-submit="submitted=true; myForm.$valid && myDialog.hide();" novalidate> 

    <div style="text-align:center;margin:0px 10px 0px 10px"> 

     <input name="rFName" ng-model="rFName" class="text-input" style="width:100%;margin-top:10px" id="rFName" placeholder="First Name" required> 
     <div style="color:red;font-size:13px;text-align:center"> 
      <span ng-show="submitted && myForm.rFName.$error.required">*required</span> 

     </div> 

     <input name="rLName" ng-model="rLName" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="Last Name" required> 
     <div style="color:red;font-size:13px;text-align:center"> 
      <span ng-show="submitted && myForm.rLName.$error.required">*required</span> 

     </div> 

     <input type="email" name="rEmail" ng-model="rEmail" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="Email" required> 
     <div style="color:red;font-size:13px;text-align:center"> 
      <span ng-show="submitted && myForm.rEmail.$error.required">*required</span> 
      <span ng-show="submitted && myForm.rEmail.$error.email">*Invalid email</span> 
     </div> 

     <input type="number" name="rPhone" ng-model="rPhone" class="text-input" style="width:100%;margin-top:10px" id="" placeholder="Contact Number" required> 
     <div style="color:red;font-size:13px;text-align:center"> 
      <span ng-show="submitted && myForm.rPhone.$error.required">*required</span> 
      <span ng-show="submitted && myForm.rPhone.$error.number">*Please enter valid phone number</span> 
     </div> 

    </div> 


    <p></p> 


    <div style="text-align:center" > 
     <ons-button style="width:35%;background:#B54747" ng-click="submitted=true; myForm.$valid && myDialog.hide();">Save</ons-button> 
     <ons-button id="cancel_btn" style="width:35%;background:#B54747" ng-click="myDialog.hide();">Cancel</ons-button> 
    </div> 

</form> 

Demo link

+0

其實這裏驗證正在發生,但錯誤消息沒有顯示,這是問題。其他頁面顯示正確的輸出。但我認爲這是Ons-Dialog元素的問題。看到上面的評論。 –

+0

您能否請設置jsfiddle來重現您的問題。 –

+0

其實我不能用ONSEN-UI框架設置JSfiddle。我認爲這是Ons-Dialog的問題。 –

相關問題