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

[Feature Request] Make FORM_KEY configurable in field #13330

Open
fisker opened this issue Jan 23, 2025 · 0 comments
Open

[Feature Request] Make FORM_KEY configurable in field #13330

fisker opened this issue Jan 23, 2025 · 0 comments

Comments

@fisker
Copy link

fisker commented Jan 23, 2025

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant