diff --git a/stdlib/widgets/formbuilder/formbuilder.opa b/stdlib/widgets/formbuilder/formbuilder.opa index d3fcb0c8..6d334c27 100644 --- a/stdlib/widgets/formbuilder/formbuilder.opa +++ b/stdlib/widgets/formbuilder/formbuilder.opa @@ -77,7 +77,6 @@ type WFormBuilder.style = type WFormBuilder.specification = { elts : list(WFormBuilder.element) ; style : WFormBuilder.style - ; process : { get_field_value : string -> string } -> void } WFormBuilder = @@ -103,10 +102,8 @@ WFormBuilder = ; hint_elt_type = {block} } - create_specification(elts : list(WFormBuilder.element), - process : { get_field_value : string -> string } -> void - ) : WFormBuilder.specification = - {~elts style=empty_style ~process} + create_specification(elts : list(WFormBuilder.element)) : WFormBuilder.specification = + {~elts style=empty_style} empty_validator : WFormBuilder.validator = input -> {success=input} @@ -324,7 +321,9 @@ WFormBuilder = hide_hint(style, id) : void = animate(style, #{hint_id(id)}, Dom.Effect.fade_out()) - html(spec : WFormBuilder.specification) : xhtml = + html(spec : WFormBuilder.specification, + process : { get_field_value : string -> string } -> void) + : xhtml = s = spec.style style(style) = WStyler.add(style, _) mk_field(~{label validator needed field_type id hint}) = @@ -382,7 +381,7 @@ WFormBuilder = | ~{ fragment } -> fragment | ~{ field } -> mk_field(field) body_form = List.map(mk_element, spec.elts) -
spec.process(~{get_field_value})} method="post"> + process(~{get_field_value})} method="post"> {body_form} @@ -394,6 +393,13 @@ WFormBuilder = | {some=~{field}} -> Dom.give_focus(#{input_id(field.id)}) | _ -> void + // TODO do we want to keep field ids as strings? Maybe introduce abstraction for them... + get_all_field_ids(spec : WFormBuilder.specification) : list(string) = + get_field_ids = + | ~{field} -> some(field.id) + | _ -> none + List.filter_map(get_field_ids, spec.elts) + get_field_value(id : string) = Dom.get_value(#{id}) diff --git a/stdlib/widgets/formbuilder/formbuilder_template_engine.opa b/stdlib/widgets/formbuilder/formbuilder_template_engine.opa index 8ef538a8..2963e6f1 100644 --- a/stdlib/widgets/formbuilder/formbuilder_template_engine.opa +++ b/stdlib/widgets/formbuilder/formbuilder_template_engine.opa @@ -66,8 +66,8 @@ FormBuilderTemplate = fields = [] // FIXME, plug-in form processing process({get_field_value=_}) = void - spec = FB.create_specification(fields, process) - form = FB.html(spec) + spec = FB.create_specification(fields) + form = FB.html(spec, process) {success = form} engine : Template.engine =