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

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

Open
MangelMaxime opened this issue Nov 8, 2019 · 0 comments
Labels

Comments

@MangelMaxime
Copy link
Contributor

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.

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

No branches or pull requests

1 participant