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 : ('a, 't) Typ.t -> 't field_ex type 't t = { name : Identifier.t; (** The internal name *) label : textI18n; placeholder : textI18n option; icon : unit option; type' : 't field_ex; required : bool; validation : validation list; criteria : string list Dsl.t option; (** Display the field when the criteria is valid *) } let name : 'ref t -> Identifier.t = fun t -> t.name let label : 'ref t -> textI18n = fun t -> t.label let placeholder : 'ref t -> textI18n option = fun t -> t.placeholder let icon : 'ref t -> unit option = fun t -> t.icon let type_ : 'ref t -> 'ref field_ex = fun t -> t.type' let required : 'ref t -> bool = fun t -> t.required let validation : 'ref t -> validation list = fun t -> t.validation let criteria : 'ref t -> string list Dsl.t option = fun t -> t.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 type_ label ?placeholder ?icon ?(required = false) ?(validation = []) ?criteria name -> { name; label; placeholder; icon; type' = type_; required; validation; criteria; } let map : ('a -> 'b) -> 'a t -> 'b t = fun f t -> let (T field_type) = t.type' in let new_type = T (Typ.map f field_type) in { t with type' = new_type }