element [Bug Report] Cascader Component restrict multiple selection

q0qdq0h2  于 2022-11-13  发布在  其他
关注(0)|答案(3)|浏览(231)

Element UI version

2.12.0

OS/Browsers version

MacOS / Chrome 79.0.3945.130

Vue version

2.6.10

https://jsfiddle.net/zqt7rk2b/

Steps to reproduce

I try to restrict multiple for just three item.

I do this by vue's watch , with the data update, the Cascader still can add selection item.

<el-cascader
               placeholder="最多选择三个"
               :show-all-levels="false"
               :options="jobCategoryOptions"
               :props="jobCatetoryProps"
               v-model="categoryIds"
 />

var Main = {
  data() {
    return {
      categoryIds: [],
      jobCatetoryProps: {
        multiple: true,
        expandTrigger: "hover",
        value: "id",
        label: "name",
        emitPath: false,
        children: "children"
      },
      jobCategoryOptions: response().data
    }
  },
  watch: {
    categoryIds: function(newVal, oldVal) {
      // limit 3 items, but not work
      if (newVal.length > 3) {
        this.categoryIds = oldVal;
      }
    },
  }
}

What is Expected?

the Cascader should restrict multiple selection for three item.

What is actually happening?

the Cascader still can add selection item.

gopyfrb3

gopyfrb31#

Translation of this issue:

Element UI version

2.12.0

OS/Browsers version

MacOS / Chrome 79.0.3945.130

Vue version

2.6.10

https://jsfiddle.net/zqt7rk2b/

Steps to reproduce

I try to restrict multiple for just three item.

I do this by vue's watch , with the data update, the Cascader still can add selection item.

<el-cascader
Placeholder = "select up to three"

:show-all-levels="false"
:options="jobCategoryOptions"

:props="jobCatetoryProps"
v-model="categoryIds"

Var Main = {

Data () {
Return {

categoryIds: [],
jobCatetoryProps: {

multiple: true,
expandTrigger: "hover",

Value: "Id",
label: "name",

emitPath: false,
children: "children"

}
jobCategoryOptions: response().data

}
}

Watch: {
categoryIds: function(newVal, oldVal) {

// limit 3 items, but not work
if (newVal.length > 3) {

this.categoryIds = oldVal;
}

}
}

}

What is Expected?

the Cascader should restrict multiple selection for three item.

What is actually happening?

the Cascader still can add selection item.

jutyujz0

jutyujz02#

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

icomxhvb

icomxhvb3#

感谢您的来信,我会尽快阅读的。 Thanks, I would read it as soon as possible~

相关问题