Design change: transformer of non-multi input-fields get two

arguments: the input-field *and* the binding value (not only the
binding value)

Rational: (a) transformers of non-multi input-fields can now access the
attribute field of the input-field record, (b) there is no real reason
why to treat multi and non-multi input-fields differently in respect
to their transformer arguments (keep design simple).

Updates of current surflets only necessary if they create their own
non-multi input-fields (with make-input-field).  Example surlfets
calculate.scm and calculate-cb.scm updated as well as standard HTML
input-fields provided by the SUrflets.
This commit is contained in:
interp 2004-07-21 20:09:37 +00:00
parent 299a4ef815
commit 15f07f8d4a
4 changed files with 16 additions and 13 deletions

View File

@ -124,7 +124,8 @@
((real-input-field-transformer real-input-field) input-field bindings))
((real-input-field-binding real-input-field bindings) =>
(lambda (binding)
((real-input-field-transformer real-input-field) (cdr binding))))
((real-input-field-transformer real-input-field)
input-field (cdr binding))))
(else
(error "no such input-field" input-field bindings)))))

View File

@ -56,10 +56,12 @@
(define set-simple-field-default!
(make-simple-default-setter simple-default?))
(define (second-arg first second) second)
;;;;;;;;;;;;;;;;;;;;
;;; Text input field
(define make-text-field
(simple-field-maker "text" "text" simple-default? identity))
(simple-field-maker "text" "text" simple-default? second-arg))
(define set-text-field-value! set-simple-field-default!)
;;;;;;;;;;;;;;;;;;;;;;
@ -67,7 +69,7 @@
(define (number-field-default? value)
(or (number? value)
(simple-default? value)))
(define (number-field-transformer string)
(define (number-field-transformer input-field string)
(or (string->number string)
(error "wrong type")))
(define make-number-field
@ -82,14 +84,14 @@
;; as it is hidden.
(define make-hidden-field
(simple-field-maker "hidden" "hidden"
simple-default? identity))
simple-default? second-arg))
(define set-hidden-field-value! set-simple-field-default!)
;;;;;;;;;;;;;;;;;;;;;;;;
;;; Password input field
(define make-password-field
(simple-field-maker "password" "password"
simple-default? identity))
simple-default? second-arg))
(define set-password-field-value! set-simple-field-default!)
;;; That's it for simple input fields.
@ -110,7 +112,7 @@
,@(sxml-attribute-attributes attributes))))
(make-input-field
name "textarea"
identity
second-arg
(make-field-attributes (and default-text)
all-attributes)
make-textarea-html-tree))))
@ -282,7 +284,7 @@
;; internal
(define (make-single-select name select-options attributes)
(make-input-field name "select"
(lambda (tag)
(lambda (input-field tag)
(cond ((find-select-option-value tag select-options)
=> identity)
(else (error "no such option." tag))))
@ -330,7 +332,7 @@
((checked? #f boolean?)
(attributes '() sxml-attribute?))
(make-input-field name "radio"
identity
second-arg
(make-field-attributes
(and checked? '(checked))
`((value ,value-string)
@ -367,7 +369,7 @@
(define (make-radio-transformer value-table)
(lambda (tag)
(lambda (input-field tag)
(cond
((string->number tag) =>
(lambda (number)
@ -420,7 +422,7 @@
checkbox-html-tree-maker))))
(define (make-checkbox-transformer value)
(lambda (tag)
(lambda (input-field tag)
(if (string=? tag "on")
value
#f)))
@ -443,7 +445,7 @@
;; button input-fields
(define (make-button type name button-caption attributes)
(make-input-field name type
identity
second-arg
(make-field-attributes
(and button-caption `(value ,button-caption))
(sxml-attribute-attributes attributes))

View File

@ -22,7 +22,7 @@
(let ((name (generate-input-field-name "operator")))
(make-input-field
name
(lambda (operator-string)
(lambda (input-field operator-string)
(cond
((assoc operator-string *operator-alist*) =>
(lambda (a) a))

View File

@ -22,7 +22,7 @@
(let ((name (generate-input-field-name "operator")))
(make-input-field
name "operator"
(lambda (operator-string)
(lambda (input-field operator-string)
(let ((operator (assoc operator-string *operator-alist*)))
(if operator
operator