form-create icon indicating copy to clipboard operation
form-create copied to clipboard

Naive-UI使用时,发现失焦无法触发表单项的校验,必须手动触发校验。

Open anyJohn opened this issue 1 year ago • 2 comments

Naive-UI使用时,发现失焦无法触发表单项的校验。

版本:

  • "@form-create/naive-ui": "^3.2.19"
  • "vue": "^3.5.13"
  • "naive-ui": "^2.41.0"

截图

Image

Image

代码

<template>
    <form-create
        :rule="testRule"
        :options="options"
        v-model:api="api"
    />
</template>
<script setup lang="ts">
import formCreate, { type Api, type Options } from '@form-create/naive-ui'
import { ref, type Ref } from 'vue'
const api: Ref<Api> = ref({} as any)
const options: Ref<Options> = ref({
    onSubmit: (model: any) => {
        console.log(model)
    }
})

const testRule = ref([
    {
        type: 'input',
        field: 'field1',
        title: 'field1',
        validate: [{ required: true, type: 'string', message: '请输入field1' }]
    },
    {
        type: 'inputNumber',
        field: 'field2',
        title: 'field2',
        validate: [
            { required: true, type: 'number', message: '请输入field2' },
            { min: 10, type: 'number', message: 'field2最小为10' }
        ]
    }
])
</script>
<style lang="less" scoped></style>

anyJohn avatar Mar 07 '25 10:03 anyJohn

add "trigger: 'blur'" in validate

emeiziying avatar Mar 10 '25 05:03 emeiziying

Resolved after adding "trigger: 'blur'" in validate

add "trigger: 'blur'" in validate

anyJohn avatar Mar 10 '25 12:03 anyJohn