MAKE-SELECT-INPUT-FIELD can now create select input fields with multiple

selections. INPUT-FIELD-VALUE will always return a (possible empty) list in
the multiple case.
This commit is contained in:
interp 2002-10-04 13:56:46 +00:00
parent eef78201f0
commit 85b0d91475
3 changed files with 52 additions and 28 deletions

View File

@ -399,31 +399,44 @@
;; preselected option: (selected) ;; preselected option: (selected)
;; changed return value: (value new-value) ;; changed return value: (value new-value)
;; returns a select input field with several options ;; returns a select input field with several options
(define (make-select-input-field options . maybe-further-attributes) (define make-select-input-field
(let ((name (generate-input-field-name "select"))) (let ((make-multiple-transformer
(optionals maybe-further-attributes (lambda (name)
((attributes XML-attribute?)) (lambda (bindings)
(make-input-field (map cdr
name (filter (lambda (binding)
identity ;FIXME[extension] refer to list elements (equal? (car binding) name))
`(select (@ ((name ,name) bindings))))))
,(and attributes (cdr attributes))))
#\newline (lambda (options . maybe-further-attributes)
,@(map (lambda (option) (optionals maybe-further-attributes
((multiple? boolean?)
(attributes XML-attribute?))
(let* ((name (generate-input-field-name "select"))
(SXML-options
(map (lambda (option)
(cond
((string-or-symbol? option)
(list 'option option))
((list? option)
(cond (cond
((string? option) ((null? (cdr option))
(list 'option option)) `(option ,option))
((list? option) ((XML-attribute? (cadr option)) ; w/attribs?
(cond `(option ,(cadr option) ,(car option)))
((null? (cdr option))
`(option ,option))
((XML-attribute? (cadr option)) ; with attributes?
`(option ,(cadr option) ,(car option)))
(else
(error "not an attribute" (cdr option)))))
(else (else
(error "not an option" option)))) (error "not an attribute" (cdr option)))))
options)))))) (else
(error "not an option" option))))
options))
(SXML `(select (@ ((name ,name)
,(if multiple? '(multiple) '())
,(and attributes (cdr attributes))))
#\newline
,SXML-options)))
(if multiple?
(make-upper-input-field (make-multiple-transformer name) SXML)
(make-input-field name identity SXML)))))))
;; returns a *list* of radio buttons ;; returns a *list* of radio buttons
(define (make-radio-input-fields values . maybe-further-attributes) (define (make-radio-input-fields values . maybe-further-attributes)
@ -509,6 +522,8 @@
#f `(@ (src ,image-source) #f `(@ (src ,image-source)
,@(if attributes (cdr attributes) '()))))) ,@(if attributes (cdr attributes) '())))))
;; <input-field>: '(input-field . <real-input-field>)
;; <real-input-field>: #{Input-field "name"}
(define (input-field-value input-field bindings) (define (input-field-value input-field bindings)
(let ((input-field (cadr input-field))) (let ((input-field (cadr input-field)))
(cond (cond

View File

@ -51,9 +51,6 @@
,(make-submit-button "Do it"))) ,(make-submit-button "Do it")))
,footer))))) ,footer)))))
(bindings (get-bindings req)) (bindings (get-bindings req))
;; No error handling as always something is selected. If
;; not, the browser did something wrong and we may yield
;; an error anyway.
(action (input-field-value select bindings))) (action (input-field-value select bindings)))
(if (string=? action action-title) (if (string=? action action-title)

View File

@ -4,6 +4,18 @@
servlets servlets
httpd-responses) httpd-responses)
(begin (begin
(define select (make-select-input-field '("a" "b" "c") #t '(@ (size 2))))
(define (main req) (define (main req)
(send-html/finish (let ((req (send-html/suspend
'(html (body (h1 "This is from servlet"))))))) (lambda (new-url)
`(html (body (h1 "This is from servlet")
(servlet-form
,new-url
,select
,(make-submit-button))
))))))
(send-html/finish
`(html (body (h1 "Result")
,(format #f "~s" (get-bindings req)))))))
))