2017-03-21 79 views
0

我的表單上有一個用戶輸入文本框。可見性基於在js文件中設置的myboolean。我也想v-validate:field_title依賴於myboolean。目前,如果v-validate:field_title =「['required']」,則該字段中必須有文本才能提交表單。使v驗證字段動態

`<div class="form-group" v-show="myboolean == 'true'"> 
     <label for="field_title">Field Title: </label> 
     <input id="field_title" 
     class="form-control field_title_typeahead title" 
     name="field_title" type="text" 
     placeholder="Select Field" 
     autocomplete="off" value="" 
     v-validate:field_title="['required']"> 
    </div>` 

回答

0

用v-if標籤圍繞這個類似乎有訣竅。

<div v-if="myboolean == 'true'"> 
     <div class="form-group"> 
       <label for="field_title">Field Title: </label> 
       <input id="field_title" 
       class="form-control field_title_typeahead title" 
       name="field_title" type="text" 
       placeholder="Select Field" 
       autocomplete="off" value="" 
       v-validate:field_title="['required']"> 
     </div> 
</div