Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

[FormBuilder] What to do with formConfig then building the form dynamically ? #3

Description

@MangelMaxime

Issue by MangelMaxime
Tuesday Nov 27, 2018 at 12:47 GMT
Originally opened as MangelMaxime/Thoth#88


The documentation explain this scenario:

let (formState, formConfig) =
    Form<Msg>
        .Create(OnFormMsg)
        .AddField(
            BasicInput
                .Create("firstname")
                .WithDefaultView()
        )
        .Build()

So caching formConfig is possible directly.

But if you have something like:

let createForm (userInfo : UserInfo) =
    Form<Msg>
        .Create(OnFormMsg)
        .AddField(
            BasicInput
                .Create("firstname")
                .WithValue(userInfo.Firstname)
                .WithDefaultView()
        )
        .Build()

Then you formConfig isn't cached by default. Current solution is to use a mutable variable to store the formConfig:

let mutable formConfig = Unchecked.defaultof<Types.Config<Msg>>

// Then to init the form
            let (state, config) =
                createForm currentUser userInfo

            formConfig <- config

            let (formState, formCmd) =
                Form.init formConfig state

Which isn't perfect. We should make formConfig cached by default and probably handle by the library in a special spaces.

One thing to take care is to destroy an old formConfig that is not useful anymore.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions