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] [date-picker] el-date-picker使用 type="daterange"时缺少name或id #16802

Open
SkywalkerJi opened this issue May 9, 2024 · 1 comment · May be fixed by #16808
Open

[Component] [date-picker] el-date-picker使用 type="daterange"时缺少name或id #16802

SkywalkerJi opened this issue May 9, 2024 · 1 comment · May be fixed by #16808

Comments

@SkywalkerJi
Copy link

SkywalkerJi commented May 9, 2024

Bug Type: Component

Environment

  • Vue Version: 3.4.26
  • Element Plus Version: 2.7.2
  • Browser / OS: Chrome 124.0.6367.119 / Windows NT 10
  • Build Tool: Vite

Reproduction

Related Component

  • el-date-picker

Reproduction Link

Docs

Steps to reproduce

<template>
  <el-radio-group v-model="size" aria-label="size control">
    <el-radio-button value="large">large</el-radio-button>
    <el-radio-button value="default">default</el-radio-button>
    <el-radio-button value="small">small</el-radio-button>
  </el-radio-group>
  <div class="demo-date-picker">
    <div class="block">
      <span class="demonstration">Default</span>
      <el-date-picker
        v-model="value1"
        type="daterange"
        range-separator="To"
        start-placeholder="Start date"
        end-placeholder="End date"
        :size="size"
      />
    </div>
    <div class="block">
      <span class="demonstration">With quick options</span>
      <el-date-picker
        v-model="value2"
        type="daterange"
        unlink-panels
        range-separator="To"
        start-placeholder="Start date"
        end-placeholder="End date"
        :shortcuts="shortcuts"
        :size="size"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const size = ref<'default' | 'large' | 'small'>('default')

const value1 = ref('')
const value2 = ref('')

const shortcuts = [
  {
    text: 'Last week',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    },
  },
  {
    text: 'Last month',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    },
  },
  {
    text: 'Last 3 months',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      return [start, end]
    },
  },
]
</script>

<style scoped>
.demo-date-picker {
  display: flex;
  width: 100%;
  padding: 0;
  flex-wrap: wrap;
}

.demo-date-picker .block {
  padding: 30px 0;
  text-align: center;
  border-right: solid 1px var(--el-border-color);
  flex: 1;
}

.demo-date-picker .block:last-child {
  border-right: none;
}

.demo-date-picker .demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}
</style>

What is Expected?

不报错

What is actually happening?

浏览器产生问题:
A form field element should have an id or name attribute
A form field element has neither an id nor a name attribute. This might prevent the browser from correctly autofilling the form.
To fix this issue, add a unique id or name attribute to a form field. This is not strictly needed, but still recommended even if you have an autocomplete attribute on the same element.

检查后可以看到是daterange状态下的el-date-picker输入框。
image

Additional comments

目前可以手动添加name解决,希望可以在组件中有默认name。

@xuyimingwork
Copy link

找到了问题了,date-picker 中不是 range 的 input 是用 el-input 实现的,而 range 的 input 用的是原生的 input,el-input 在不传入 id 时会自动生成 id,而原生 input 没有该类功能。

xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 10, 2024
fix time-picker type range input elements without default id value

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 10, 2024
fix time-picker type range input elements without default id value

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 10, 2024
fix time-picker type range input elements without default id value

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 11, 2024
add input id check for time-picker in range

adjust non range test cases to right place

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 11, 2024
fix time-picker type range input elements without default id value

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 11, 2024
add input id check for time-picker in range

adjust non range test cases to right place

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 13, 2024
fix time-picker type range input elements without default id value

closed element-plus#16802
xuyimingwork added a commit to xuyimingwork/element-plus that referenced this issue May 13, 2024
add input id check for time-picker in range

adjust non range test cases to right place

closed element-plus#16802
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

Successfully merging a pull request may close this issue.

2 participants