package bonsai
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=0c4a714146073f421f1a6179561f836b45d8dc012c743207d3481ea63bef74bf
doc/bonsai.web_ui_form/Bonsai_web_ui_form/index.html
Module Bonsai_web_ui_formSource
Bonsai-web-forms has its own view type so that it can build a more structured view of the form. You can convert it to a Vdom node with the to_vdom* functions.
return produces a bonsai form that will always produce the same value. set and normalize will do nothing to the form provided by this.
return_error produces a form that always fails validation.
val view_as_vdom :
?on_submit:'a Submit.t ->
?editable:[ `Yes_always | `Currently_yes | `Currently_no ] ->
'a t ->
Bonsai_web.Vdom.Node.tview_as_vdom produces the vdom representation of the form.
editable defaults to `Yes_always, which should be used when form input can't be disabled. `Currently_yes allows editing, but generates less diff when toggled with `Currently_no. When editable is `Currently_no, the view is wrapped in a fieldset that disables all of the inputs in the form.
Regardless of the value of editable, scheduling the Form.set effect will still change the values in the form.
Known bugs: While setting editable to `Currently_no prevents modification of most browser-builtin input elements, some custom form elements like the drag-and-drop, multiselect, and removing items using the pills in typeahead-multi for don't currently respect this and can be modified anyway. Work is underway to fix these.
set fills the form with the provided value, setting the contents of form-elements if possible
normalize sets the contents of a form to its current value. This only impacts values that have a "normalized" form. For example, a float-producing textbox being normalized might go from displaying "1.000" to "1."
Combines two forms into another one that produces both values from the inputs in tupled form.
project is the powerhouse of the library; Using this function, you can change the type produced. Think of it like map.
parse_exnis a function that converts "forwards". As its name implies, you're free (and encouraged to) throw exceptions when the type conversion would fail.unparsegoes in the opposite direction. This one must not throw.
Example:
let _ : int Form.t =
project
(a: string Form.t)
~parse_exn:Int.of_string
~unparse:Int.to_stringThe same as project except that the parse function is Or_error returning.
validate can provide additional validation of a value, but unlike project or project', it doesn't change the type of the resulting form
Same as label, but it lets you use an arbitrary vdom node instead of just a string.
Same as tooltip, but it lets you use an arbitrary vdom node instead of just a string.
Sometimes it's nice to collect a bunch of forms under a label. Because 'a t can represent multiple rows of forms, the group and group' functions put those rows underneath a header.Record_builder
group-name
sub1 _________
sub2 _________Same as group, but it lets you use an arbitrary vdom node instead of just a string.
optional takes a 'a t and produces a 'a option t when given a "some detector" and a token "none" value. is_some none must be false.
Example:
let _ : string option t =
optional
(a: string t)
~is_some:(Fn.non String.is_empty)
~none:""val optional' :
'a t ->
parse:('a -> 'b option Core.Or_error.t) ->
unparse:('b -> 'a) ->
none:'a ->
'b option tAn alternative "optional form" construction function; optional' gives you the ability to produce the full set of parse options:
- Ok (Some b)
- Ok None
- Error error] while also converting to another type (
'a -> 'b option) at the same time.
Record_builder is the primary way to compose form values using this library.
Unlike the rest of the API which operates on values of type Form.t value values, they operate on Form.t Value.t, and typically return Computation.t.