<el-select v-model.trim="param.dataType" placeholder="" @change="onType" > <el-option v-for="item in dictionaryTypeList" :key="item.value" :label="item.label" :value="item.value" /> </el-select> <span class="c-grid-form__label u-required">参数</span> <el-input v-model.trim="param.dataValue" placeholder="请输入参数" />选择选择领一个值的时候,下方的输入框已经存在的值清除,可以输入新的值
时间: 2024-01-16 20:04:50 浏览: 209
您可以在`onType`方法里添加相应的逻辑,当用户选择了一个新的选项时,将`param.dataValue`的值清空。例如:
```
onType() {
this.param.dataValue = ''; // 清空输入框的值
}
```
这样当用户选择了一个新的选项时,就会清空输入框的值,让用户可以输入新的值。
相关问题
<el-form-item label="联系人" prop="contactsList"> <el-button type="primary" link :disabled="dialogType === 'check'" @click="handleContactsInfo">添加</el-button> <el-table :data="infoForm.contactsList" border stripe size="small"> <el-table-column label="姓名" prop="ContactsName"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsName" maxlength="20" placeholder="请填写姓名" show-word-limit ></el-input> </template> </el-table-column> <el-table-column label="部门" prop="ContactsDepartment"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsDepartment" maxlength="20" show-word-limit placeholder="请填写部门" ></el-input> </template> </el-table-column> <el-table-column label="职务" prop="ContactsDuty"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsDuty" maxlength="20" show-word-limit placeholder="请填写职务" ></el-input> </template> </el-table-column> <el-table-column label="联系方式" prop="ContactNumber"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactNumber" maxlength="50" show-word-limit placeholder="请填写联系方式" ></el-input> </template> </el-table-column> <el-table-column label="操作" width="56px"> <template #default="{ $index }"> <el-button type="primary" link size="small" :disabled="dialogType === 'check'" @click="handleRemove($index)" > 删除 </el-button> </template> </el-table-column> </el-table> </el-form-item> 该表单初始就有一个,且至少保留一个,对表单内姓名一栏进行必填校验
你可以通过在 el-input 元素的前面添加一个 el-form-item 元素,并设置 prop 属性为 "ContactsName",然后在 el-input 元素中添加一个 :rules 属性来进行必填校验。以下是示例代码:
```html
<el-table-column label="姓名" prop="ContactsName">
<template #default="{ row }">
<el-form-item prop="ContactsName" :rules="[{ required: true, message: '请填写姓名' }]">
<el-input
:disabled="dialogType === 'check'"
v-model.trim="row.ContactsName"
maxlength="20"
placeholder="请填写姓名"
show-word-limit
></el-input>
</el-form-item>
</template>
</el-table-column>
```
这样,当用户没有填写姓名时,表单会显示错误提示信息。
<template slot-scope="scope"> <el-form-item :prop="'list.' + scope.$index + '.controlok'" :rules="fromDataRules.controlok" > <el-input v-if="scope.row.controluse === 'S2F21'" :disabled=" scope.row.iscontrol === false || scope.row.iscontrol == null || scope.row.iscontrol == '' " v-model="scope.row.controlok" filterable clearable /> <el-select v-else v-model="scope.row.controlok" :disabled=" scope.row.iscontrol === false || scope.row.iscontrol == null || scope.row.iscontrol == '' " :placeholder="t('web_ems_tip_pleaseInput')" filterable clearable > <el-option v-for="item in identifyingList" :key="item.id" :label="item" :value="item" /> </el-select> </el-form-item> </template>表单验证fromDataRules.controlok自定义若该行的iscontrol的值是true并且controlok的值为空时,提示请输入。代码怎么写
你可以在 `fromDataRules` 中添加一个自定义规则来实现该功能,代码如下:
```javascript
fromDataRules: {
controlok: [
{
required: true,
message: '请输入',
trigger: 'blur',
validator: (rule, value, callback) => {
let index = rule.field.split('.')[1];
let row = this.list[index];
if (row.iscontrol === true && (value === undefined || value.trim() === '')) {
callback(new Error('请输入'));
} else {
callback();
}
}
}
]
}
```
在该规则中,我们定义了一个自定义验证函数 `validator`,它会在输入框失去焦点时被调用。该函数会根据当前行的 `iscontrol` 值和 `controlok` 的值来判断是否需要进行验证。如果需要验证且 `controlok` 值为空,则会调用 `callback(new Error('请输入'))` 来提示用户输入。否则,调用 `callback()` 来表示验证通过。
在模板中,我们需要绑定 `fromDataRules.controlok` 规则,在 `el-form-item` 组件中添加 `prop` 属性,并将其值设为 `'list.' + scope.$index + '.controlok'`,这样该规则就会应用到该行的 `controlok` 属性上。
```html
<template slot-scope="scope">
<el-form-item
:prop="'list.' + scope.$index + '.controlok'"
:rules="fromDataRules.controlok">
<el-input
v-if="scope.row.controluse === 'S2F21'"
:disabled="scope.row.iscontrol === false || scope.row.iscontrol == null || scope.row.iscontrol == ''"
v-model="scope.row.controlok"
filterable
clearable />
<el-select
v-else
v-model="scope.row.controlok"
:disabled="scope.row.iscontrol === false || scope.row.iscontrol == null || scope.row.iscontrol == ''"
:placeholder="t('web_ems_tip_pleaseInput')"
filterable
clearable>
<el-option
v-for="item in identifyingList"
:key="item.id"
:label="item"
:value="item" />
</el-select>
</el-form-item>
</template>
```
阅读全文