Skip to content

uni-forms rules不能正常工作 #963

Closed
@weickdev

Description

@weickdev
<template>
	<view class="container">
		<uni-forms ref="valiForm" :modelValue="formData" label-position="top" :rules="rules">
			<uni-forms-item label="Email" name="email">
				<uni-easyinput type="text" v-model="formData.email" placeholder="Enter Your Email" />
			</uni-forms-item>
		</uni-forms>
		<button @click="onSubmit">Submit</button>
	</view>
</template>

<script setup>
	
	import { ref } from 'vue'
	const valiForm = ref()
	const formData = ref({})
	const rules = ref({
		email: {
			rules: [
				{
					required: true,
					errorMessage: 'Enter your email',
				},
				{
					format: 'email',
					errorMessage: 'Enter a right email',
				},
				{
					minLength: 1,
					maxLength: 10,
					errorMessage: 'Email should be less than 10 characters.'
				}
			]
		}
	})
	const onSubmit = () => {
		valiForm.value.validate().then(res=>{
			console.log('表单数据信息:', res);
		}).catch(err =>{
			console.log('表单错误信息:', err);
		})
	}
</script>

<style>
	       
</style>

以上代码,只有required工作正常。如果输入不是email,错误提示还说提示required的错误提示,minLength和maxLength规则完全不起作用

Activity

GRCmade

GRCmade commented on Mar 14, 2025

@GRCmade
Contributor

hello , 你是在哪个平台的执行的, 版本是多少 ?我尝试运行了一下代码,三种情况都是正常,这个是三种情况的运行截图:

  1. require
Image
  1. email
Image
  1. length
Image
GRCmade

GRCmade commented on Mar 31, 2025

@GRCmade
Contributor

长时间未回复,关闭 issue,如果还存在这个问题,可以重新打开

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @mehaotian@weickdev@GRCmade

      Issue actions

        uni-forms rules不能正常工作 · Issue #963 · dcloudio/uni-ui