6.1.3 Form0
(require conscript/form0) | package: conscript |
This module reprovides nearly all the bindings in the forms library for creating forms in your study pages, as well as some additional conveniences for using that library.
See the Forms Recipe for steps and examples to combine these procedures into working forms in your study steps.
In addition to the tutorials in this documentation, see (part ("(lib forms/forms.scrbl)" "top")) for a tutorial that walks through the functionality of Forms.
syntax
(form+submit [id formlet-expr] ...)
Each id should be a variable declared with defvar or similar, and each formlet-expr should be one of the values in (part ("(lib forms/forms.scrbl)" "formlets")), or an ensure expression combining one of those formlets with one or more (part ("(lib forms/forms.scrbl)" "validators")).
> (defvar my-name) > (defvar my-middle-name) > (defvar my-age)
> (define-values (form-data on-submit) (form+submit [my-name (ensure binding/text (required))] [my-middle-name binding/text] [my-age (ensure binding/number (required))]))
procedure
(form f action render [ #:id id #:enctype enctype #:combine combine-proc #:defaults defaults]) → xexpr? f : form? action : (-> void?) render : (-> (widget-renderer/c) xexpr?) id : string? = "" enctype : string? = "multipart/form-data"
combine-proc : (-> any/c any/c any/c any/c) =
(λ (k v1 v2) (if (pair? v1) (append v1 (list v2)) (list v1 v2))) defaults : hash? = (hash)
Identical to the form from congame/components/study except for the default combine-proc: when there are multiple bindings for the same field, this procedure’s default combine-proc combines all the bindings for that field into a list (as described in the documentation for form-run).
procedure
(required-unless pred) →
(-> (or/c string? #f) (or/c (cons/c 'ok any/c) (cons/c 'err string?))) pred : (-> any/c)
procedure
(checkbox [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-date [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-datetime [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-email [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-number [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-range [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-text [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(input-time [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
procedure
(textarea [label] #:attributes attrs) → widget/c
label : (or/c string? #f) = #f attrs : null
> ((checkbox) "agree" #f null)
'(div
((class "field-group"))
(label () "Agree" (input ((type "checkbox") (name "agree")))))
> ((input-time) "arrived" #f null)
'(div
((class "field-group"))
(label () "Arrived" (input ((type "time") (name "arrived")))))
procedure
(radios options [label] #:attributes attrs) → widget/c
options : radio-options/c label : (or/c string? #f) = #f attrs : null
procedure
(select options label #:attributes attrs) → widget/c
options : radio-options/c label : string? attrs : null
procedure
(checkboxes options #:attributes attrs) → widget/c
options : radio-options/c attrs : null
> (define opts '(("high" . "Take the high road") ("low" . "Go low"))) > ((radios opts "Metaphorical highway selection") "road" #f null)
'(div
((class "group"))
(label
((class "radio-group"))
"Metaphorical highway selection"
(div
(label
(input ((type "radio") (name "road") (value "high")))
"Take the high road")
(label (input ((type "radio") (name "road") (value "low"))) "Go low"))))
> ((checkboxes opts) "roadboxen" #f null)
'(div
((class "group"))
(div
((class "div"))
(label
()
(input ((type "checkbox") (name "roadboxen") (value "high")))
"Take the high road")
(label
()
(input ((type "checkbox") (name "roadboxen") (value "low")))
"Go low")))
procedure
(make-autofill v) → xexpr?
v : any/c
Use this when rendering step pages to instruct the bot how to fill in certain fields.
> (make-autofill (hasheq 'example (hasheq 'name "Frank" 'mood "Delicate"))) '(meta ((name "formular-autofill") (content "")))
> (parameterize ([current-user-bot? #t]) (make-autofill (hasheq 'example (hasheq 'name "Frank" 'mood "Delicate"))))
'(meta
((name "formular-autofill")
(content
"#hasheq((example . #hasheq((mood . \"Delicate\") (name . \"Frank\"))))")))