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

setValues as a method #35

Closed
RBleyenberg opened this issue Mar 24, 2023 · 2 comments
Closed

setValues as a method #35

RBleyenberg opened this issue Mar 24, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@RBleyenberg
Copy link

RBleyenberg commented Mar 24, 2023

Looking at the api docs we have a setValue but no setValues.

what i like todo is open a modal which hold a form and set all the values at once's from a object given as argument.

atm i'm doing it like this

  const openModal = $((country: ICountry) => {
      modal.isOpen = true,
      modal.title = 'country',
      countryForm.internal.fields.id.value = country.id,
      countryForm.internal.fields.code.value = country.code,
      countryForm.internal.fields.name.value = country.name
  });

But would like todo something like this

  const openModal = $((country: ICountry) => {
      modal.isOpen = true,
      modal.title = 'country',
      countryForm.values = country
       or
      setValues('countryForm', country)
  });

I'm i overlooking something in the api docs ?

@fabian-hiller fabian-hiller self-assigned this Mar 24, 2023
@fabian-hiller fabian-hiller added the enhancement New feature or request label Mar 24, 2023
@fabian-hiller
Copy link
Owner

That is correct, currently there is no setValues method yet. However, I actually started working on it yesterday. Since the implementation is not as simple as it seems at first sight I cannot say at the moment when I will release it. Until then I recommend to call setValue for each field separately to avoid invalidating the state of the form. setValue does not only update the value. If you are interested, you can find the API reference and source code at the following links.

API reference: https://modularforms.dev/api/setValue
Source code: https://github.com/fabian-hiller/modular-forms/blob/main/packages/qwik/src/methods/setValue.ts

@fabian-hiller
Copy link
Owner

The setValues method is now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants