Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weickdev opened this issue Oct 23, 2024 · 0 comments
Open

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

weickdev opened this issue Oct 23, 2024 · 0 comments

Comments

@weickdev
Copy link

weickdev commented Oct 23, 2024

<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规则完全不起作用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant