2016-12-04 254 views
0

我试图禁用此消息“请填写此字段。”:如何禁用Angular必填字段msg?

enter image description here

我想用我自己的自定义消息;我怀疑这是来自Angular,但似乎无法禁用它。我想过通过css禁用它,但不知道类或id。我试图做'检查元素',但是当我尝试时,这个消息会消失。

这里是html表格,如果有帮助。

<form name="personalForm" role="form" ng-submit="updatePersonal(updatePersonalForm)" 
      ng-init="updatePersonalForm = {first_name: userFirstName, 
      last_name: userLastName, job_title: userJobTitle, company_name: userCompanyName, 
      location: userLocation, website: userWebsite}"> 

      <div class="auth-body"> 
       <div class="row" style="margin: 0;"> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <div class="form-group personal-form-group"> 
        <label>first name</label> 
        <input type="text" name="first_name" 
        required class="form-control" ng-model="updatePersonalForm.first_name" 
        ng-class="{ 'error-input': personalForm.first_name.$invalid}"> 
        </div> 
       </div> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <div class="form-group personal-form-group"> 
        <label>last name</label> 
        <input type="text" name="last_name" 
        required class="form-control" ng-model="updatePersonalForm.last_name" 
        ng-class="{ 'error-input': personalForm.last_name.$invalid}"> 
        </div> 
       </div> 
       </div> 

       <div class="row" style="margin: 0;"> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <div class="form-group personal-form-group"> 
        <label>job title</label> 
        <input type="text" name="job_title" ng-model="updatePersonalForm.job_title" 
        class="form-control"> 
        </div> 
       </div> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <div class="form-group personal-form-group"> 
        <label>location</label> 
        <input type="text" name="location" ng-model="updatePersonalForm.location" 
        class="form-control"> 
        </div> 
       </div> 
       </div> 

       <div class="row" style="margin: 0;"> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <div class="form-group personal-form-group"> 
        <label>company name</label> 
        <input type="text" name="company_name" ng-model="updatePersonalForm.company_name" 
        class="form-control"> 
        </div> 
       </div> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <div class="form-group personal-form-group"> 
        <label>personal website</label> 
        <input type="text" name="personal_website" ng-model="updatePersonalForm.website" 
        class="form-control"> 
        </div> 
       </div> 
       </div> 

       <div class="row" style="margin: 0;"> 
       <div class="col-sm-6 account-input-container" style="padding: 0;"> 
        <button type="submit" class="bubble-btn submit-btn pull-left" style="float: none !important;">update</button> 
       </div> 
       </div> 
      </div> 
      </form> 

我能够打印出这些选项,但似乎无法找到所需的味精的选项,也许它甚至没有。

enter image description here

预先感谢您的帮助!

+0

您是否在下面的答案中尝试了建议? – Aruna

+0

@阿鲁纳刚刚做了,非常感谢! – medev21

回答

1

上述验证由HTML5而不是AngularJS发起。您可以通过如下的form添加novalidate属性关闭这个功能,

<form novalidate name="personalForm" role="form" ng-submit="updatePersonal(updatePersonalForm)" 
      ng-init="updatePersonalForm = {first_name: userFirstName, 
      last_name: userLastName, job_title: userJobTitle, company_name: userCompanyName, 
      location: userLocation, website: userWebsite}"> 

</form> 
0

将novalidate添加到您的表单标记。这将防止默认的HTML5验证。

<form action=" " novalidate> 
    //form body 
</form> 
0

如果要将此行为表单内各个领域做到这一点:

<form name="formName" novalidate> 
    <!-- all fields... --> 
</form> 

...或...如果您想为特定字段设置该行为,请对这些字段执行相同的操作。当您设置一个特定领域的属性,它如果要禁用特定领域刚刚脱下requiredng-required指令覆盖父窗体行为

<form name="formName"> 
    <label> Enter your text here </label> 
    <input type="text" formnovalidate /> 
</form> 
0