[Bese-devel] Re: A field class for multiple select inputs

Marijn Haverbeke marijnh at gmail.com
Wed Jun 7 11:54:57 UTC 2006


Grrr, there was still debug code in that snipped. How clumsy! Here's it
again without the extra <:ai call.

(defclass multiple-select-field (select-field)
  ()
  (:default-initargs :name (random-string 8) :client-value ()))

(defmethod render ((field multiple-select-field))
  (<:input :type "hidden" :value "x"
           :name (make-new-callback
                  (lambda (value)
                    (declare (ignore value))
                    (do ((vars (slot-value (context.request *context*)
'parameters) (cdr vars))
                         (result ()))
                        ((null vars) (setf (client-value field) result))
                      (if (string= (caar vars) (name field))
                          (push (cdar vars) result))))))
  (<:select :name (name field) :tabindex (tabindex field) :multiple t
            (setf (data-map field) (build-data-map field))
            (render-options field)))

(defmethod render-options ((field multiple-select-field))
  (dolist* ((key-string . value) (data-map field))
    (<:option :value key-string
              :selected  (member key-string (client-value field) :test
#'string=)
              (render-value field value))))

(defmethod value ((field multiple-select-field))
  (mapcar (lambda (x)
            (cdr (assoc x (data-map field) :test #'string=)))
          (client-value field)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20060607/1832186c/attachment.html>


More information about the bese-devel mailing list