Skip to content

Commit

Permalink
[feature] WFormBuilder: added get_all_field_ids + API improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
akoprow committed Jul 25, 2011
1 parent 449ad7a commit 41f66cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions stdlib/widgets/formbuilder/formbuilder.opa
Expand Up @@ -77,7 +77,6 @@ type WFormBuilder.style =
type WFormBuilder.specification = type WFormBuilder.specification =
{ elts : list(WFormBuilder.element) { elts : list(WFormBuilder.element)
; style : WFormBuilder.style ; style : WFormBuilder.style
; process : { get_field_value : string -> string } -> void
} }


WFormBuilder = WFormBuilder =
Expand All @@ -103,10 +102,8 @@ WFormBuilder =
; hint_elt_type = {block} ; hint_elt_type = {block}
} }


create_specification(elts : list(WFormBuilder.element), create_specification(elts : list(WFormBuilder.element)) : WFormBuilder.specification =
process : { get_field_value : string -> string } -> void {~elts style=empty_style}
) : WFormBuilder.specification =
{~elts style=empty_style ~process}


empty_validator : WFormBuilder.validator = empty_validator : WFormBuilder.validator =
input -> {success=input} input -> {success=input}
Expand Down Expand Up @@ -324,7 +321,9 @@ WFormBuilder =
hide_hint(style, id) : void = hide_hint(style, id) : void =
animate(style, #{hint_id(id)}, Dom.Effect.fade_out()) 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 s = spec.style
style(style) = WStyler.add(style, _) style(style) = WStyler.add(style, _)
mk_field(~{label validator needed field_type id hint}) = mk_field(~{label validator needed field_type id hint}) =
Expand Down Expand Up @@ -382,7 +381,7 @@ WFormBuilder =
| ~{ fragment } -> fragment | ~{ fragment } -> fragment
| ~{ field } -> mk_field(field) | ~{ field } -> mk_field(field)
body_form = List.map(mk_element, spec.elts) body_form = List.map(mk_element, spec.elts)
<form onsubmit={_ -> spec.process(~{get_field_value})} method="post"> <form onsubmit={_ -> process(~{get_field_value})} method="post">
{body_form} {body_form}
</> </>


Expand All @@ -394,6 +393,13 @@ WFormBuilder =
| {some=~{field}} -> Dom.give_focus(#{input_id(field.id)}) | {some=~{field}} -> Dom.give_focus(#{input_id(field.id)})
| _ -> void | _ -> 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) = get_field_value(id : string) =
Dom.get_value(#{id}) Dom.get_value(#{id})


Expand Down
4 changes: 2 additions & 2 deletions stdlib/widgets/formbuilder/formbuilder_template_engine.opa
Expand Up @@ -66,8 +66,8 @@ FormBuilderTemplate =
fields = [] fields = []
// FIXME, plug-in form processing // FIXME, plug-in form processing
process({get_field_value=_}) = void process({get_field_value=_}) = void
spec = FB.create_specification(fields, process) spec = FB.create_specification(fields)
form = FB.html(spec) form = FB.html(spec, process)
{success = form} {success = form}


engine : Template.engine = engine : Template.engine =
Expand Down

0 comments on commit 41f66cd

Please sign in to comment.