3***@qq.com
3***@qq.com
  • 发布:2022-02-28 18:15
  • 更新:2023-02-28 13:53
  • 阅读:1071

#插件讨论# 【 uni-forms 表单 - DCloud前端团队 】使用uni-datetime-picker,没有进行选择时候不进行校验

分类:uni-app
关联插件: uni-forms 表单

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: '',}]},
2022-02-28 18:15 负责人:无 分享
已邀请:
BoredApe

BoredApe - 有问题就会有答案。

请上传一个能重现问题的测试工程

  • 3***@qq.com (作者)

    文件已上传

    2022-03-01 09:48

3***@qq.com

3***@qq.com (作者)

            submit() {  
                this.$refs.form.validate().then(async resForm => {  
                    console.log('校验完成',resForm)  
                }).catch(err => {  
                    console.error('表单错误信息:', err);  
                })  
            }
3***@qq.com

3***@qq.com (作者)

3***@qq.com

3***@qq.com (作者)

问题已解决,uni-forms的v-model需要设置一个值,:modelValue可能无效

  • x***@qq.com

    uni-forms的v-model怎么设置一个值?我怎么不行呀,题主

    2023-02-28 14:07

x***@qq.com

x***@qq.com

uni-forms的v-model怎么设置一个值?我怎么不行呀,题主

要回复问题请先登录注册