blob: 42a2d2a65149e13ab5053190b1c7d7f6446fb081 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
type textI18n = (string * string) list
(** A label is just an association list*)
type validation = { rule : string list Dsl.t; message : textI18n }
type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex
type 't t =
| F : {
name : Identifier.t;
t : ('db, 'ocaml, 't) Types.t;
label : textI18n;
placeholder : textI18n option;
icon : unit option;
required : bool;
validation : validation list;
criteria : string list Dsl.t option;
(** Display the field when the criteria is valid *)
}
-> 't t
(** The record is a GADT so that [t] keeps its type parameters ['db] and
['ocaml] existential. The type stays abstract in the interface. *)
let name : 'ref t -> Identifier.t = fun (F f) -> f.name
let label : 'ref t -> textI18n = fun (F f) -> f.label
let placeholder : 'ref t -> textI18n option = fun (F f) -> f.placeholder
let icon : 'ref t -> unit option = fun (F f) -> f.icon
let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T f.t
let required : 'ref t -> bool = fun (F f) -> f.required
let validation : 'ref t -> validation list = fun (F f) -> f.validation
let criteria : 'ref t -> string list Dsl.t option = fun (F f) -> f.criteria
let create :
't field_ex ->
textI18n ->
?placeholder:textI18n ->
?icon:unit ->
?required:bool ->
?validation:validation list ->
?criteria:string list Dsl.t ->
Identifier.t ->
't t =
fun (T typ) label ?placeholder ?icon ?(required = false) ?(validation = [])
?criteria name ->
F { name; t = typ; label; placeholder; icon; required; validation; criteria }
|