vant icon indicating copy to clipboard operation
vant copied to clipboard

[Feature Request] Make `FORM_KEY` configurable in `field`

Open fisker opened this issue 11 months ago • 0 comments

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:

  1. Use Symbol.for like I already did
  2. Allow pass form to van-field (Personlly preferred)
  3. 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>

fisker avatar Jan 23 '25 10:01 fisker