MangelMaxime / Fable.Form

Home Page:https://mangelmaxime.github.io/Fable.Form/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onSubmit payload

joahim opened this issue · comments

What is the reason why the onSubmit payload is not of the type Values? For example, if I have:

type Values =
    { Name : string
      Email : string }

and the two corresponding fields defined in the form, the onSubmit will be defined as let onSubmit name email = ....

Why use the list of fields here and not the Values type? Similar to the Value field function in the field record definition (e.g. Value = fun values -> values.Name).

I'm still struggling to understand how the library works internally so any insight into this part would be great. Thank you!

Values type is used to store the Form field values which in general are not strongly typed.

For example, in Fable.Form.Simple all of the input type use string to store their current values.

However, when checking if the field values are valid and to submit the form you are receiving the result of the Parser Example of parser.

This mean that for an Email field for example, you are not submitting a string but an Email type.

In resume, you are using Values to store the field current value and when submitting the form you can received strongly typed types.


Also this is not because you are storing a field values that you want to retrieve it.

For example, in the Sign up example, the value of Repeat password is not passed onSubmit. It is only used to check that the user provided the same value for Password and Repeat password.

Thank you very much! Makes sense now :-) What a clever way to handle forms.

While investigating I also came across the article about the Elm variant of the package. It does not cover many things your cover in the documentation but I think it does a good job of describing the basic idea of a library and it may be useful for others if you include a link to it in your docs.

Hello,
yes I really like how it works for composing the forms with just function :)

Indeed, the linked article is a bit more comprehensive/detailed than my quick How to use