uni-forms:1.3.2
uni-datetime-picker:2.2.2
在uni-forms中使用uni-datetime-picker,没有进行任何操作的情况下进行提交校验,不做错误提示,设置value的默认值也不行。如果填写了其他需要校验的内容,则直接校验通过,但是相关参数没有出现在回调中,只有进行编辑后,才会恢复正常的操作。
<view class="content">
<uni-forms ref="form" :rules="rules" :border="true">
<uni-forms-item :label="formInfo.label" :name="formInfo.field" v-for="(formInfo,index) in infoforms" :key='index'
:required="formInfo.isShowRequired" :label-width="85">
<uni-datetime-picker v-if="formInfo.form_type == 'DATE_TIME'"
:type="formInfo.inputType == null ? 'datetime': formInfo.inputType" v-model="formInfo.value"/>
<uni-easyinput v-if="formInfo.form_type == 'EDIT_STRING' || formInfo.form_type == 'STRING'"
:type="formInfo.inputType == null ? 'text': formInfo.inputType" v-model="formInfo.value"
:placeholder="'请输入'+formInfo.label" :unit="formInfo.unit" :maxlength="formInfo.inputType == 'textarea' ? 120 : 20"
:disabled="(formInfo.enable != null && !formInfo.enable) || formInfo.form_type == 'STRING'" trim="all"/>
</uni-forms-item>
</uni-forms>
<button type="default" @click="submit">保存</button>
</view>
data() {
return {
infoforms:[
{label: '面访时间',field: 'createDate',value: '',form_type: 'DATE_TIME',isShowRequired:true},
{label: '年龄',field: 'age',value: '',form_type: 'EDIT_STRING',inputType:'number',isShowRequired:true},
],
rules: {
createDate: {rules: [{required: true,errorMessage: '请选择时间',}]},
age:{rules: [{required: true,errorMessage: '123',}]},
},
}
},
补充个问题,部分表单会出现这个问题,目前没发现规律。没有使用云开发开发,表单会做错误提示,xx数据不在数据库中,尽管该字段不参与校验,我目前的解决办法是将对应的字段都写出来,类似以下。
gender:{rules: [{required: false,errorMessage: '',}]},
age:{rules: [{required: false,errorMessage: '',}]},
dockingName:{rules: [{required: false,errorMessage: '',}]},
dockingTel:{rules: [{required: false,errorMessage: '',}]},
3***@qq.com (作者)
文件已上传
2022-03-01 09:48