Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module type Config = {
- type state;
- type fields;
- let lens: list((fields, state => ReForm.Value.t, (state, ReForm.Value.t) => state));
- };
- module Create = (Config: Config) => {
- module Form = ReForm.Create(Config);
- type fieldSchema = {
- field: Config.fields,
- label: string,
- validator: ReForm.Validation.validation(Form.values),
- };
- let component = ReasonReact.statelessComponent("QuickForm");
- let make =
- (
- ~onSubmit,
- ~onFormStateChange=?,
- ~validate=?,
- ~schema: list(fieldSchema),
- ~initialState,
- ~renderField,
- ~renderSubmit,
- ~i18n=?,
- _children,
- ) => {
- ...component,
- render: _self =>
- <Form
- onSubmit
- initialState
- ?onFormStateChange
- ?validate
- ?i18n
- schema=(
- List.map(fieldSchema => (fieldSchema.field, fieldSchema.validator), schema)
- )>
- ...(
- reform =>
- <div>
- (
- List.map(
- fieldSchema =>
- renderField(
- ~label=fieldSchema.label,
- ~onChange=reform.handleChange,
- ~getErrorForField=reform.getErrorForField,
- ),
- schema,
- )
- |> Array.of_list
- |> ReasonReact.arrayToElement
- )
- (renderSubmit(~onClick=reform.handleSubmit))
- </div>
- )
- </Form>,
- };
- };
Add Comment
Please, Sign In to add comment