我怎样才能让我的单选按钮成为必需的?

问题描述 投票:0回答:1

我希望此单选按钮以必须选择其中一个选项的方式工作。

<v-col cols="12" class="pt-0 py-0 d-flex align-center">
    <v-radio-group
   v-model="modulesData.fatality"
          column
                                                    :disabled="!editionStatus || !hasPermissionTo('incident')">
                                                    <label class="py-1 input-field__label_1 d-flex align-center pt-auto mx-0">
                                                        Was there a fatality associated with the incident?</label>
                                                    <v-radio
                                                        label="Yes"
                                                        :value="true"
                                                    ></v-radio>
                                                    <v-radio
                                                        label="No"
                                                        :value="false"
                                                    ></v-radio>
                                                </v-radio-group>
                                            </v-col>

我希望找到必须选择其中一个框的解决方案。

vue.js vue-component vuejs3 vuetify.js vuex
1个回答
0
投票

验证是通过 <radio-group> 上的

rules
道具完成的。大多数表单组件共享相同类型的验证,您将在 v-form 文档页面上找到更多关于规则验证的文档

<v-radio-group
  v-model="modulesData.fatality"
  column
  :rules="[v => v !== null || 'Field required']"
>
  <label class="py-1 input-field__label_1 d-flex align-center pt-auto mx-0">
    Was there a fatality associated with the incident?
  </label>
  <v-radio label="Yes" :value="true"></v-radio>
  <v-radio label="No" :value="false"></v-radio>
</v-radio-group>

如果您的单选选项使用真/假值,您需要确保

modulesData.fatality
的初始值都不是(例如 null 或 undefined)

© www.soinside.com 2019 - 2024. All rights reserved.