[go: nahoru, domu]

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

[Component] [select] select multiple 会自动触发一次表单校验 #17279

Closed
flonny opened this issue Jun 20, 2024 · 3 comments · Fixed by #17606
Closed

[Component] [select] select multiple 会自动触发一次表单校验 #17279

flonny opened this issue Jun 20, 2024 · 3 comments · Fixed by #17606
Labels

Comments

@flonny
Copy link
flonny commented Jun 20, 2024

Bug Type: Component

Environment

  • Vue Version: 3.4.29
  • Element Plus Version: 2.7.5
  • Browser / OS: chrome 125.0.6422.176
  • Build Tool: Vite

Reproduction

Related Component

  • el-select

Reproduction Link

Element Plus Playground

Steps to reproduce

<template>
    <el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto" status-icon>
      <el-form-item label="Activity name" prop="name">
        <el-input v-model="ruleForm.name" />
      </el-form-item>
      <el-form-item label="Activity zone" prop="region">
        <el-select clearable multiple v-model="ruleForm.region" placeholder="Activity zone">
          <el-option label="Zone one" value="shanghai" />
          <el-option label="Zone two" value="beijing" />
        </el-select>
      </el-form-item>
    </el-form>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
interface RuleForm {
  name: string
  region?: string[]
}

const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({
  name: 'Hello',
})

const rules = reactive<FormRules<RuleForm>>({
  region: [
    {
      required: true,
      message: 'Please select Activity zone',
      trigger: 'change',
    },
  ],

})
</script>

What is Expected?

region 不设置初始值时,不触发校验

What is actually happening?

region 会触发表单校验

Additional comments

(empty)

@zhuchaoling
Copy link
Contributor

加上默认值 就不报红了
demo

@Panzer-Jack
Copy link
Contributor

没有填写默认值 会自动转换成Array,在源码里加了一个标志位可以解决这个问题:
PR: #17284

@flonny
Copy link
Author
flonny commented Jun 20, 2024

PR:#17286

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