From 15f07f8d4a90657c705051bc47b22cd135ee69fd Mon Sep 17 00:00:00 2001 From: interp Date: Wed, 21 Jul 2004 20:09:37 +0000 Subject: [PATCH] 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. --- scheme/httpd/surflets/input-fields.scm | 3 ++- .../httpd/surflets/surflet-input-fields.scm | 22 ++++++++++--------- web-server/root/surflets/calculate-cb.scm | 2 +- web-server/root/surflets/calculate.scm | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/scheme/httpd/surflets/input-fields.scm b/scheme/httpd/surflets/input-fields.scm index f52f792..dbf5a84 100644 --- a/scheme/httpd/surflets/input-fields.scm +++ b/scheme/httpd/surflets/input-fields.scm @@ -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))))) diff --git a/scheme/httpd/surflets/surflet-input-fields.scm b/scheme/httpd/surflets/surflet-input-fields.scm index 27939d5..bc58346 100644 --- a/scheme/httpd/surflets/surflet-input-fields.scm +++ b/scheme/httpd/surflets/surflet-input-fields.scm @@ -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)) diff --git a/web-server/root/surflets/calculate-cb.scm b/web-server/root/surflets/calculate-cb.scm index 0a43ef3..5170277 100644 --- a/web-server/root/surflets/calculate-cb.scm +++ b/web-server/root/surflets/calculate-cb.scm @@ -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)) diff --git a/web-server/root/surflets/calculate.scm b/web-server/root/surflets/calculate.scm index feeab07..17caeb1 100644 --- a/web-server/root/surflets/calculate.scm +++ b/web-server/root/surflets/calculate.scm @@ -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