diff --git a/collects/tests/web-server/formlets-test.rkt b/collects/tests/web-server/formlets-test.rkt index 846bb4a518..f7a0938f2b 100644 --- a/collects/tests/web-server/formlets-test.rkt +++ b/collects/tests/web-server/formlets-test.rkt @@ -127,7 +127,9 @@ (make-request #"GET" (string->url "http://test.com") empty (delay bs) - #f "127.0.0.1" 80 "127.0.0.1")))] + #f "127.0.0.1" 80 "127.0.0.1"))) + (define (test-display f) + (formlet-display f))] (test-suite "Input" @@ -209,6 +211,18 @@ (test-equal? "textarea-input" (test-process (textarea-input) (list (make-binding:form #"input_0" #"value"))) "value") + (test-equal? "textarea-input" + (test-display (textarea-input)) + '((textarea ([name "input_0"]) ""))) + (test-equal? "textarea-input" + (test-display (textarea-input #:rows 80)) + '((textarea ([name "input_0"] [rows "80"]) ""))) + (test-equal? "textarea-input" + (test-display (textarea-input #:cols 80)) + '((textarea ([name "input_0"] [cols "80"]) ""))) + (test-equal? "textarea-input" + (test-display (textarea-input #:cols 80 #:rows 70)) + '((textarea ([name "input_0"] [rows "70"] [cols "80"]) ""))) (test-equal? "to-string" (test-process (to-string (required (text-input))) (list (make-binding:form #"input_0" #"value"))) diff --git a/collects/web-server/formlets/input.rkt b/collects/web-server/formlets/input.rkt index 919587347e..51241e9fdc 100644 --- a/collects/web-server/formlets/input.rkt +++ b/collects/web-server/formlets/input.rkt @@ -122,9 +122,9 @@ ; XXX button (define (multiselect-input l - #:multiple? [multiple? #t] - #:selected? [selected? (λ (x) #f)] - #:display [display (λ (x) x)]) + #:multiple? [multiple? #t] + #:selected? [selected? (λ (x) #f)] + #:display [display (λ (x) x)]) (define value->element (make-hasheq)) (define i 0) (define (remember! e) @@ -161,46 +161,56 @@ (cross (pure first) (multiselect-input l - #:multiple? #f - #:selected? selected? - #:display display))) + #:multiple? #f + #:selected? selected? + #:display display))) -(define (textarea-input) - (to-string - (required +(define (textarea-input + #:rows [rows #f] + #:cols [cols #f]) + (to-string + (required (make-input (lambda (n) (list 'textarea - (list (list 'name n)) + (list* (list 'name n) + (append + (filter list? + (list (and rows (list 'rows (number->string rows))) + (and cols (list 'cols (number->string cols))))))) "")))))) (provide/contract [multiselect-input (->* (sequence?) (#:multiple? boolean? - #:selected? (any/c . -> . boolean?) - #:display (any/c . -> . pretty-xexpr/c)) + #:selected? (any/c . -> . boolean?) + #:display (any/c . -> . pretty-xexpr/c)) (formlet/c (listof any/c)))] [select-input (->* (sequence?) (#:selected? (any/c . -> . boolean?) - #:display (any/c . -> . pretty-xexpr/c)) + #:display (any/c . -> . pretty-xexpr/c)) (formlet/c any/c))] - [textarea-input (-> (formlet/c string?))] + [textarea-input (() + (#:rows number? + #:cols number?) + . ->* . + (formlet/c string?))] [text-input (() - (#:value (or/c false/c bytes?) - #:size (or/c false/c exact-nonnegative-integer?) - #:max-length (or/c false/c exact-nonnegative-integer?) - #:read-only? boolean? - #:attributes (listof (list/c symbol? string?))) - . ->* . - (formlet/c (or/c false/c binding?)))] + (#:value (or/c false/c bytes?) + #:size (or/c false/c exact-nonnegative-integer?) + #:max-length (or/c false/c exact-nonnegative-integer?) + #:read-only? boolean? + #:attributes (listof (list/c symbol? string?))) + . ->* . + (formlet/c (or/c false/c binding?)))] [password-input (() - (#:value (or/c false/c bytes?) - #:size (or/c false/c exact-nonnegative-integer?) - #:max-length (or/c false/c exact-nonnegative-integer?) - #:read-only? boolean? - #:attributes (listof (list/c symbol? string?))) - . ->* . - (formlet/c (or/c false/c binding?)))] + (#:value (or/c false/c bytes?) + #:size (or/c false/c exact-nonnegative-integer?) + #:max-length (or/c false/c exact-nonnegative-integer?) + #:read-only? boolean? + #:attributes (listof (list/c symbol? string?))) + . ->* . + (formlet/c (or/c false/c binding?)))] [checkbox ((bytes? boolean?) (#:attributes (listof (list/c symbol? string?))) . ->* . diff --git a/collects/web-server/scribblings/formlets.scrbl b/collects/web-server/scribblings/formlets.scrbl index 62e694d77a..2408450f60 100644 --- a/collects/web-server/scribblings/formlets.scrbl +++ b/collects/web-server/scribblings/formlets.scrbl @@ -303,7 +303,8 @@ These @tech{formlet}s are the main combinators for form input. This @tech{formlet} renders using an INPUT element with the PASSWORD type and the attributes given in the arguments. } -@defproc[(textarea-input) +@defproc[(textarea-input [#:rows rows (or/c false/c number?) #f] + [#:cols cols (or/c false/c number?) #f]) (formlet/c string?)]{ This @tech{formlet} renders using an TEXTAREA element. }