6.2.2 Formular: forms and fields
(require congame/components/formular) | |
package: congame-core |
A field is a special value that, when used inside a study form, renders as an input element. When the user submits the form, the field yields whatever value the user has entered as a Racket value.
procedure
(formular-field? v) → boolean?
v : any/c
procedure
(formular-autofill bot-id) → void?
bot-id : any/c
procedure
(input-list fields) → formular-field?
fields : (listof formular-field?)
For example, the following code creates two input-number fields:
(set! myvals (input-list (list (input-number) (input-number))))
When the user enters two numeric values (say, -3 and 9) and submits the form, myvals will contain '(-3 9).
procedure
(input-number [ label #:min min #:max max #:step step #:required? req] #:validators validators [ #:attributes attribs]) → formular-field? label : (or/c #f string?) = #f min : real? = -inf.0 max : real? = +inf.0 step : integer? = 1 req : (or/c string? boolean?) = #t validators : '() attribs : (listof (list/c symbol? string?)) = '()
procedure
(input-range [ label #:min min #:max max #:step step #:required? req] #:validators validators [ #:attributes attribs]) → formular-field? label : (or/c #f string?) = #f min : real? = -inf.0 max : real? = +inf.0 step : integer? = 1 req : (or/c string? boolean?) = #t validators : '() attribs : (listof (list/c symbol? string?)) = '()
If step is provided, then using the stepper arrows or slider will increase or decrease the value by that amount (though the value is not guaranteed to be a multiple of step).
If required? is not #f, the field must contain data before the form can be submitted.
procedure
(checkbox label [ #:required? required? #:attributes attrs]) → formular-field? label : (or/c #f string?) required? : any/c = #t attrs : (listof (list/c symbol? string?)) = null
procedure
(input-text [ label #:required? req] #:validators validators [ #:attributes attrs]) → formular-field? label : (or/c #f string?) = #f req : (or/c string? boolean?) = #t validators : '() attrs : (listof (list/c symbol? string?)) = '()
procedure
(textarea label [ #:required? req] #:validators validators [ #:attributes attrs]) → formular-field? label : (or/c #f string?) req : (or/c string? boolean?) = #t validators : '() attrs : (listof (list/c symbol? string?)) = '()
Use attrs to specify the size of the text box in rows and columns:
(textarea "Label" #:attributes '((rows "5") (cols "33")))
procedure
(input-date label [ #:required? req] #:validators validators [ #:attributes attrs]) → formular-field? label : (or/c #f string?) req : (or/c string? boolean?) = #t validators : '() attrs : (listof (list/c symbol? string?)) = '()
procedure
(input-time label [ #:required? req] #:validators validators [ #:attributes attrs]) → formular-field? label : (or/c #f string?) req : (or/c string? boolean?) = #t validators : '() attrs : (listof (list/c symbol? string?)) = '()
Date values are returned in strings of the form "yyyy-mm-dd". Time values are returned as strings of the form "hh:mm" (24-hour format).
If required? is not #f, the field must contain text before the form can be submitted. Any attrs will be used as HTML attributes in the field’s <input> tag.
syntax
(input-file arg)
arg : any/c
syntax
(make-checkboxes arg)
arg : any/c
syntax
(make-radios arg)
arg : any/c
syntax
(make-radios-with-other arg)
arg : any/c
syntax
(make-sliders arg)
arg : any/c
syntax
(select/inline arg)
arg : any/c
procedure
(map-result arg) → any/c
arg : any/c
syntax
(map-result* arg)
arg : any/c
}
6.2.2.1 Form tools
(require (submod congame/components/formular tools)) |