package bonsai
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=24c4c3149280abd639034ce3acf60e475a772202099e965be8bd8902524573ef
doc/bonsai.web_ui_form/Bonsai_web_ui_form/index.html
Module Bonsai_web_ui_form
module View : sig ... endBonsai-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.
val return : 'a -> 'a treturn produces a bonsai form that will always produce the same value. set and normalize will do nothing to the form provided by this.
val return_error : Core.Error.t -> _ treturn_error produces a form that always fails validation.
val map_error : 'a t -> f:(Core.Error.t -> Core.Error.t) -> 'a tval value : 'a t -> 'a Core.Or_error.tval value_or_default : 'a t -> default:'a -> 'aval is_valid : _ t -> boolis_valid returns true if value would return Ok.
module Submit : sig ... endval 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.
val set : 'a t -> 'a -> unit Ui_effect.tset fills the form with the provided value, setting the contents of form-elements if possible
val normalize : _ t -> unit Ui_effect.tnormalize 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_stringval project' :
'a t ->
parse:('a -> 'b Core.Or_error.t) ->
unparse:('b -> 'a) ->
'b tThe same as project except that the parse function is Or_error returning.
val validate : 'a t -> f:('a -> unit Core.Or_error.t) -> 'a tvalidate 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.
module Record_builder : sig ... endRecord_builder is the primary way to compose form values using this library.
module Dynamic : sig ... endUnlike 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.
module Expert : sig ... endmodule Private : sig ... endmodule Elements : sig ... endmodule Typed : sig ... endThe functions in this module can be hard to understand Please look at the examples in lib/bonsai/examples/forms/typed.ml