From c2f8e4c0fe3e133941a2c7cf1ef72ae0a212a72c Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Wed, 20 Oct 2010 09:09:20 -0700 Subject: [PATCH] Adding attributes to select-input --- collects/tests/web-server/formlets-test.rkt | 14 ++++++++++ collects/web-server/formlets/input.rkt | 27 ++++++++++++------- .../web-server/scribblings/formlets.scrbl | 6 +++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/collects/tests/web-server/formlets-test.rkt b/collects/tests/web-server/formlets-test.rkt index ab5ad60ccc..ac2837398b 100644 --- a/collects/tests/web-server/formlets-test.rkt +++ b/collects/tests/web-server/formlets-test.rkt @@ -383,6 +383,13 @@ (option ((value "0")) 1) (option ((value "1")) 2) (option ((value "2")) 3)))) + (test-equal? "multiselect-input" + (test-display (multiselect-input (list 1 2 3) #:attributes '([test "val"]))) + '((select + ((multiple "true") (name "input_0") (test "val")) + (option ((value "0")) 1) + (option ((value "1")) 2) + (option ((value "2")) 3)))) (test-equal? "multiselect-input" (test-display (multiselect-input (list 1 2 3) #:multiple? #t)) '((select @@ -434,6 +441,13 @@ (option ((value "0")) 1) (option ((value "1")) 2) (option ((value "2")) 3)))) + (test-equal? "select-input" + (test-display (select-input (list 1 2 3) #:attributes '([test "val"]))) + '((select + ((name "input_0") [test "val"]) + (option ((value "0")) 1) + (option ((value "1")) 2) + (option ((value "2")) 3)))) (test-equal? "select-input" (test-display (select-input (list 1 2 3) #:selected? even?)) '((select diff --git a/collects/web-server/formlets/input.rkt b/collects/web-server/formlets/input.rkt index c26405eebf..4a07f58c60 100755 --- a/collects/web-server/formlets/input.rkt +++ b/collects/web-server/formlets/input.rkt @@ -174,6 +174,7 @@ attrs)))))) (define (multiselect-input l + #:attributes [attrs empty] #:multiple? [multiple? #t] #:selected? [selected? (λ (x) #f)] #:display [display (λ (x) x)]) @@ -198,7 +199,8 @@ (make-input* (lambda (name) `(select (,@(if multiple? '([multiple "true"]) empty) - [name ,name]) + [name ,name] + ,@attrs) ,@(for/list ([(vn e) (in-hash value->element)]) (define v (number->string vn)) `(option ([value ,v] @@ -208,11 +210,13 @@ ,(display e)))))))) (define (select-input l + #:attributes [attrs empty] #:selected? [selected? (λ (x) #f)] #:display [display (λ (x) x)]) (cross (pure first) (multiselect-input l + #:attributes attrs #:multiple? #f #:selected? selected? #:display display))) @@ -280,20 +284,25 @@ . ->* . (formlet/c (or/c false/c binding?)))] [button ((bytes? bytes?) - (#:disabled boolean? - #:value (or/c false/c bytes?) - #:attributes (listof (list/c symbol? string?))) + (#:disabled + boolean? + #:value (or/c false/c bytes?) + #:attributes (listof (list/c symbol? string?))) . ->* . (formlet/c (or/c false/c binding?)))] [multiselect-input ((sequence?) - (#:multiple? boolean? - #:selected? (any/c . -> . boolean?) - #:display (any/c . -> . pretty-xexpr/c)) + (#:attributes + (listof (list/c symbol? string?)) + #:multiple? boolean? + #: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)) + (#:attributes + (listof (list/c symbol? string?)) + #:selected? (any/c . -> . boolean?) + #:display (any/c . -> . pretty-xexpr/c)) . ->* . (formlet/c any/c))] [textarea-input (() diff --git a/collects/web-server/scribblings/formlets.scrbl b/collects/web-server/scribblings/formlets.scrbl index b3825d39e9..6814c8c0e5 100755 --- a/collects/web-server/scribblings/formlets.scrbl +++ b/collects/web-server/scribblings/formlets.scrbl @@ -367,18 +367,20 @@ These @tech{formlet}s are the main combinators for form input. } @defproc[(multiselect-input [l sequence?] + [#:attributes attrs (listof (list/c symbol? string?)) empty] [#:multiple? multiple? boolean? #t] [#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)] [#:display display (any/c . -> . xexpr/c) (λ (x) x)]) (formlet/c list?)]{ - This @tech{formlet} renders using an SELECT element with an OPTION for each element of the sequence. If @racket[multiple?] is @racket[#t], then multiple options may be selected. An element is selected if @racket[selected?] returns @racket[#t]. Elements are displayed with @racket[display]. + This @tech{formlet} renders using an SELECT element with the attributes given with an OPTION for each element of the sequence. If @racket[multiple?] is @racket[#t], then multiple options may be selected. An element is selected if @racket[selected?] returns @racket[#t]. Elements are displayed with @racket[display]. } @defproc[(select-input [l sequence?] + [#:attributes attrs (listof (list/c symbol? string?)) empty] [#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)] [#:display display (any/c . -> . xexpr/c) (λ (x) x)]) (formlet/c any/c)]{ - This @tech{formlet} renders using an SELECT element with an OPTION for each element of the sequence. An element is selected if @racket[selected?] returns @racket[#t]. Elements are displayed with @racket[display]. + This @tech{formlet} renders using an SELECT element with the attributes given with an OPTION for each element of the sequence. An element is selected if @racket[selected?] returns @racket[#t]. Elements are displayed with @racket[display]. } @defproc[(required [f (formlet/c (or/c false/c binding?))])