ElemeFE / element

A Vue.js 2.0 UI Toolkit for Web
https://element.eleme.io/
MIT License
54.1k stars 14.64k forks source link

[Feature Request] Inject the form model into the custome validator function #19554

Open divasatanica opened 4 years ago

divasatanica commented 4 years ago

Existing Component

Component Name

el-form

Description

Without model in validator function, I have to use this.xxx or $refs to access the model itself. It's inconvenient when I use config-like style to write a form validation.Especially when the config and the form component codes are in different repos which communicate with server's json response.

e.g

in repo1 there's component's code:

<el-form>
  <el-input/>
</el-form>

in repo2 there's form items' config:

{
  label: 'xxx',
  rule: [
    validator(rule, value, callback) {
        // how to access another field's value? Can I still use "this" keyword?
    }
  ]
}

I cannot access other fields in the scene like this. Thank you.

element-bot commented 4 years ago

Translation of this issue:

Existing Component

yes

Component Name

el-form

Description

Without model in validator function, I have to use this.xxx or $refs to access the model itself. It's inconvenient when I use config-like style to write a form validation.Especially when the config and the form component codes are in different repos which communicate with server's json response.

E.g in repo1 there's component's code:


<el-form>

<el-input/>
</el-form>

` ` ` `
in repo2 there's form items' config:

```javascript
{

label: 'xxx',
rule: [

validator(rule, value, callback) {
// how to access another field's value? Can I still use this?

}
]

}
` ` ` `

I cannot access other fields in the scene like this.
Thank you.
stale[bot] commented 3 years ago

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.