Adding attributes to select-input

This commit is contained in:
Jay McCarthy 2010-10-20 09:09:20 -07:00
parent 8fb23b0825
commit c2f8e4c0fe
3 changed files with 36 additions and 11 deletions

View File

@ -383,6 +383,13 @@
(option ((value "0")) 1) (option ((value "0")) 1)
(option ((value "1")) 2) (option ((value "1")) 2)
(option ((value "2")) 3)))) (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-equal? "multiselect-input"
(test-display (multiselect-input (list 1 2 3) #:multiple? #t)) (test-display (multiselect-input (list 1 2 3) #:multiple? #t))
'((select '((select
@ -434,6 +441,13 @@
(option ((value "0")) 1) (option ((value "0")) 1)
(option ((value "1")) 2) (option ((value "1")) 2)
(option ((value "2")) 3)))) (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-equal? "select-input"
(test-display (select-input (list 1 2 3) #:selected? even?)) (test-display (select-input (list 1 2 3) #:selected? even?))
'((select '((select

View File

@ -174,6 +174,7 @@
attrs)))))) attrs))))))
(define (multiselect-input l (define (multiselect-input l
#:attributes [attrs empty]
#:multiple? [multiple? #t] #:multiple? [multiple? #t]
#:selected? [selected? (λ (x) #f)] #:selected? [selected? (λ (x) #f)]
#:display [display (λ (x) x)]) #:display [display (λ (x) x)])
@ -198,7 +199,8 @@
(make-input* (make-input*
(lambda (name) (lambda (name)
`(select (,@(if multiple? '([multiple "true"]) empty) `(select (,@(if multiple? '([multiple "true"]) empty)
[name ,name]) [name ,name]
,@attrs)
,@(for/list ([(vn e) (in-hash value->element)]) ,@(for/list ([(vn e) (in-hash value->element)])
(define v (number->string vn)) (define v (number->string vn))
`(option ([value ,v] `(option ([value ,v]
@ -208,11 +210,13 @@
,(display e)))))))) ,(display e))))))))
(define (select-input l (define (select-input l
#:attributes [attrs empty]
#:selected? [selected? (λ (x) #f)] #:selected? [selected? (λ (x) #f)]
#:display [display (λ (x) x)]) #:display [display (λ (x) x)])
(cross (cross
(pure first) (pure first)
(multiselect-input l (multiselect-input l
#:attributes attrs
#:multiple? #f #:multiple? #f
#:selected? selected? #:selected? selected?
#:display display))) #:display display)))
@ -280,20 +284,25 @@
. ->* . . ->* .
(formlet/c (or/c false/c binding?)))] (formlet/c (or/c false/c binding?)))]
[button ((bytes? bytes?) [button ((bytes? bytes?)
(#:disabled boolean? (#:disabled
#:value (or/c false/c bytes?) boolean?
#:attributes (listof (list/c symbol? string?))) #:value (or/c false/c bytes?)
#:attributes (listof (list/c symbol? string?)))
. ->* . . ->* .
(formlet/c (or/c false/c binding?)))] (formlet/c (or/c false/c binding?)))]
[multiselect-input ((sequence?) [multiselect-input ((sequence?)
(#:multiple? boolean? (#:attributes
#:selected? (any/c . -> . boolean?) (listof (list/c symbol? string?))
#:display (any/c . -> . pretty-xexpr/c)) #:multiple? boolean?
#:selected? (any/c . -> . boolean?)
#:display (any/c . -> . pretty-xexpr/c))
. ->* . . ->* .
(formlet/c (listof any/c)))] (formlet/c (listof any/c)))]
[select-input ((sequence?) [select-input ((sequence?)
(#:selected? (any/c . -> . boolean?) (#:attributes
#:display (any/c . -> . pretty-xexpr/c)) (listof (list/c symbol? string?))
#:selected? (any/c . -> . boolean?)
#:display (any/c . -> . pretty-xexpr/c))
. ->* . . ->* .
(formlet/c any/c))] (formlet/c any/c))]
[textarea-input (() [textarea-input (()

View File

@ -367,18 +367,20 @@ These @tech{formlet}s are the main combinators for form input.
} }
@defproc[(multiselect-input [l sequence?] @defproc[(multiselect-input [l sequence?]
[#:attributes attrs (listof (list/c symbol? string?)) empty]
[#:multiple? multiple? boolean? #t] [#:multiple? multiple? boolean? #t]
[#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)] [#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)]
[#:display display (any/c . -> . xexpr/c) (λ (x) x)]) [#:display display (any/c . -> . xexpr/c) (λ (x) x)])
(formlet/c list?)]{ (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?] @defproc[(select-input [l sequence?]
[#:attributes attrs (listof (list/c symbol? string?)) empty]
[#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)] [#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)]
[#:display display (any/c . -> . xexpr/c) (λ (x) x)]) [#:display display (any/c . -> . xexpr/c) (λ (x) x)])
(formlet/c any/c)]{ (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?))]) @defproc[(required [f (formlet/c (or/c false/c binding?))])