GithubHelp home page GithubHelp logo

Comments (13)

fabian-hiller avatar fabian-hiller commented on May 16, 2024 2

I received an answer in the TypeScript Discord and am now checking if the given solution works for Modular Forms.

from modular-forms.

sachaw avatar sachaw commented on May 16, 2024 1

No rush, thanks man

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024 1

Sorry. I haven't gotten around to it yet. I'll get back to you as soon as I find time for it.

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

Can you share a code sample with me so that I can understand your problem even better?

from modular-forms.

sachaw avatar sachaw commented on May 16, 2024

Thanks for the reply, here's an outline:

  1. I define a schema that inherits from an external class: https://github.com/meshtastic/web/blob/master/src/validation/config/position.ts inherits from https://js.meshtastic.org/classes/Protobuf.Config_PositionConfig.html
  2. I have a "form generator" that takes a generic(the validation schema from earlier) and a schema to define the physical layout: https://github.com/meshtastic/web/blob/master/src/components/PageComponents/Config/Position.tsx
  3. Finally the generator itself (currently using react-hook-form): https://github.com/meshtastic/web/blob/master/src/components/Form/DynamicForm.tsx https://github.com/meshtastic/web/blob/master/src/components/Form/DynamicFormField.tsx

Hopefully this is clear enough, thanks.

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

Is your problem that the derived type is an interface and Modular Forms throws an error when you pass it as generic or does your problem relate to validating the form inputs?

from modular-forms.

sachaw avatar sachaw commented on May 16, 2024

The former. I am unable to use your previous guidance of using a type instead of an interface

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

Unfortunately, I don't know any solution for this at the moment. To make the form values type-safe even with nested objects and arrays, I use a recursive type and this approach leads to problems when using interfaces. I will ask for advice in the TypeScript Discord. However, it is uncertain if there is a solution for this as described in #2. I will report here as soon as I have an answer.

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

I have been busy with other things the last few days. I hope to give you feedback on this over the weekend.

from modular-forms.

sachaw avatar sachaw commented on May 16, 2024

Found a workaround:
The yup validation library has ObjectSchema that allows deriving a schema from an external class definition.
So maybe this issue can be converted to requesting support for yup

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

Thanks for the info! Do you have a code example? Do you also work with Yup and need adapters for validation with Modular Forms?

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

All solutions I know so far to be able to support interfaces reduce type safety. I have again experimented a bit, but have not come to a satisfactory solution.

from modular-forms.

fabian-hiller avatar fabian-hiller commented on May 16, 2024

I'm temporarily closing the issue until there are signs that changes to our code can fix the problem.

from modular-forms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.