vant
vant copied to clipboard
[Feature Request] Make `FORM_KEY` configurable in `field`
What problem does this feature solve?
I'm working on a project that uses van-field and bundles as a separate js file.
When I put my bundled component in van-form, it can't inherit the labelWidth/labelAlign and other props. Since the FORM_KEY (a symbol) is bundled and it's not the same value as the one used in van-form.
My current workaround is to patch the package and change the value of FORM_KEY from Symbol('van-form') to Symbol.for('van-form').
Possible solutions:
- Use
Symbol.forlike I already did - Allow pass
formtovan-field(Personlly preferred) - Allow pass the
FORM_KEY
What does the proposed API look like?
If we choose option 1. The components don't need do any changes.
If we choose option 2. It will be used like
<script setup>
const form = useTemplateRef('form')
</script>
<template>
<van-form ref="form">
<my-wrapped-field :form></my-wrapped-field>
</van-form>
</template>
If we choose option 3. It will be used like
<script setup>
import {FORM_KEY} from 'vant'
</script>
<template>
<van-form>
<my-wrapped-field :form-key="FORM_KEY"></my-wrapped-field>
</van-form>
</template>