Skip to content
Browse files

[enhance] stdlib/FormBuilder: markup compat. with new Bootstrap.

  • Loading branch information...
1 parent c27148b commit 0ce9977964935ef222e7109687ec442eca21997c @akoprow akoprow committed May 24, 2012
Showing with 21 additions and 15 deletions.
  1. +21 −15 stdlib/widgets/formbuilder/formbuilder.opa
View
36 stdlib/widgets/formbuilder/formbuilder.opa
@@ -1,5 +1,5 @@
/*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of OPA.
@@ -106,7 +106,8 @@ type WFormBuilder.form =
}
type WFormBuilder.style =
- { field_complete_style : bool -> WStyler.styler
+ { form_style : WStyler.styler
+ ; field_complete_style : bool -> WStyler.styler
; field_right_col_style : WStyler.styler
; label_style : bool -> WStyler.styler
; input_style : bool -> WStyler.styler
@@ -158,7 +159,8 @@ WFormBuilder =
/** {1 Styling} */
empty_style : WFormBuilder.style =
- { field_complete_style(_) = WStyler.empty
+ { form_style = WStyler.empty
+ ; field_complete_style(_) = WStyler.empty
; field_right_col_style = WStyler.empty
; label_style(_) = WStyler.empty
; input_style(ok) = if ok then WStyler.empty else {class=["error"]}
@@ -172,11 +174,12 @@ WFormBuilder =
}
bootstrap_style : WFormBuilder.style =
- { field_complete_style(ok) = {class=["clearfix"] ++ if ok then [] else ["error"]}
- ; field_right_col_style = {class=["input"]}
- ; label_style(_) = WStyler.empty
+ { form_style = {class=["form-horizontal"]}
+ ; field_complete_style(ok) = {class=["control-group"] ++ if ok then [] else ["error"]}
+ ; field_right_col_style = {class=["controls"]}
+ ; label_style(_) = {class=["control-label"]}
; input_style(ok) = if ok then WStyler.empty else {class=["error"]}
- ; hint_style = {class=["help-block"]}
+ ; hint_style = {class=["help-inline"]}
; error_style = WStyler.empty
; non_required_style = WStyler.empty
; required_style = WStyler.empty
@@ -298,6 +301,8 @@ WFormBuilder =
uri_accessor = string_converter(_, _, Uri.of_string)
+ /** {1 Field renderers} */
+
render_text_input(~{data initial_value}, f) =
add_initial_value(
<input type="text" id={data.ids.input_id} />,
@@ -391,7 +396,7 @@ WFormBuilder =
}
| {renderForm ~body ~on_submit} ->
// FIXME, {Basic}/{Normal}
- xhtml = form_html(params.id, state, {Basic}, body, on_submit)
+ xhtml = form_html(params, state, {Basic}, body, on_submit)
{ return = xhtml
; instruction = {unchanged}
}
@@ -632,40 +637,41 @@ WFormBuilder =
builder.mk_field({label=label_xhtml input=input_xhtml hint=hint_xhtml err=err_xhtml data=rdata})
@private
- form_html( form_id : string
+ form_html( config : WFormBuilder.form_config
, fld_checkers : list(WFormBuilder.field_checker)
, form_type : {Basic} / {Normal}
, body : xhtml
, process_form : WFormBuilder.form_data -> void
) : xhtml =
- rec for_all_lazy(f, l) =
+ rec for_all_eager(f, l) =
match l with
| [] -> true
| [hd | tl] ->
- match (f(hd), for_all_lazy(f, tl)) with
+ match (f(hd), for_all_eager(f, tl)) with
| ({true}, {true}) -> true
| _ -> false
go(fd) =
// we don't use List.for_all, as we want to enforce evaluation of all fields
// (and not stop when the first error is found)
- all_ok = for_all_lazy((v -> v()), fld_checkers)
+ all_ok = for_all_eager((v -> v()), fld_checkers)
if all_ok then
process_form(fd)
else
void
form_body = <fieldset>{body}</>
match form_type
| {Basic} ->
- <form id={form_id} action="#" onsubmit={_ -> go({SimpleForm})}
+ <form id={config.id} action="#" onsubmit={_ -> go({SimpleForm})}
method="get" options:onsubmit="prevent_default">
{form_body}
- </form>
+ </>
+ |> add_style(config.style.form_style)
| {Normal} ->
process(data) =
do Scheduler.push( -> go({FileUploadForm=data}))
void
config = {Upload.default_config() with
- ~form_body ~process form_id=form_id}
+ ~form_body ~process form_id=config.id}
Upload.html(config)
}}

0 comments on commit 0ce9977

Please sign in to comment.
Something went wrong with that request. Please try again.