Skip to content

Provide reducers/reviviers for devalue in superForm/superValidate functions #423

Closed
@ktarmyshov

Description

@ktarmyshov

Is your feature request related to a problem? Please describe.
I'm using Decimal.js in zod schemas. When I use the superForm with dataType='json', posting data fails during devalue.stringify, because it cannot serialize custom type "Decimal".

Describe the solution you'd like
Feature request: provide possibility to pass reducers/revivers to superForm/superValidate to parse the request data accordingly.

Describe alternatives you've considered

    async onSubmit(input) {
      // Reduce custom types before submitting
      const formData = await superFormResult.validateForm();
      if (formData.valid) {
        const formJsonData = JSON.parse(JSON.stringify(formData.data));
        input.jsonData(formJsonData);
      }
    },

I also tried to fork and npm-link the devalue package for sveltekit (to provide default reducers/revivers for sveltekit), but superforms is using 4.3.3 and sveltekit 5.0.0 (which may still be different in the future). Even if I "override" the dependency to use 5.0.0, this one instantiated in a different (memory) context and default reducers/revivers working for sveltekit are empty for superforms - so "no go".

Additional context
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    doneImplemented enhancementsenhancementNew feature or requestnextWill be implemented in the next release

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions