[Bese-devel] what don't i understand about select-field?
Ties Stuij
cjstuij at gmail.com
Tue May 16 13:31:03 UTC 2006
Greetings,
I've been looking at the select classes in form.lisp and it seems to
me there is a lot of double work going on while the benifit is not
quite clear to me. Since you have your key-value pair ready already,
why make an index also? Especially with entities like hash tables or
alists which are supposed to have just one key to retrieve to begin
with.
Also i didn't really get the mapping-select abstraction, since it
implements its only method, render-options, exactly the same as
select-field, just with different names.
Anyway as practice i made a select field which brings the amount of
forms needed down from 12 to 4 (see below). It's the alist-select
field from form.lisp except for that the value you're after is now
already in client-value. On top of that i've built simpler select
field, which in functionality is the same as a normal select-field.
For the 'selected' attribute of options it compares the value, but
that could easily be changed to key.
As i said i made it for practice, but perhaps we could use these to
replace the select fields of form.lisp? hash-table-select and
plist-select are easily converted i think and the end result is faster
and easier to read/use.
But then again i probably missed the thing that's handy/good/practical
about the current setup.
;; simple-select-field
(defclass simple-select-field (generic-html-input)
((data-set :accessor data-set :initarg :data-set
:documentation "An alist of values this select chooses
from.")
(test-fn :accessor test-fn :initarg :test-fn :initform #'string=
:documentation "function to compare for :selected"))
(:documentation "Form field used for selecting one value from a
list of available options."))
(defmethod render ((field simple-select-field))
(<:select :name (make-new-callback
(lambda (value)
(setf (client-value field) value)))
(render-options field)))
(defgeneric render-options (select-field)
(:documentation "Function used to render the list of options of
a select field."))
(defmethod render-options ((field simple-select-field))
(dolist* ((key-string . value) (data-set field))
(<:option :value value
:selected (funcall (test-fn field) (client-value
field) value)
(<:ah key-string))))
;; simpler-select-field
(defclass simpler-select-field (simple-select-field) ()
(:documentation "needs just a list to render an option field, with the same
value for the value as the name"))
(defmethod render-options ((field simpler-select-field))
(dolist* (value (data-set field))
(<:option :value value
:selected (funcall (test-fn field) (client-value
field) value)
(<:ah value))))
greets,
Ties
More information about the bese-devel
mailing list