[Bese-devel] Events for input field objects

Marijn Haverbeke marijnh at gmail.com
Wed Jun 7 13:37:23 UTC 2006


(I got a bounce for this mail, so I'm re-sending it... if you're lucky you
aren't getting it twice.)


--------- Forwarded message ----------
From: Marijn Haverbeke <marijnh at gmail.com>
Date: Jun 7, 2006 2:58 PM
Subject: Events for input field objects
To: bese-devel at common-lisp.net

Hey,

I added some stuff to the generic-html-input class to allow client code to
register extra events on the form elements. If anybody is actually looking
at the code I'm mailing here, tell me, and I'll try to actually create a
decent diff the next time. Is just pasting diffs into an email the way to do
that, or do you attach them? Or maybe there's some kind of special darcs
format?

What this does is add an extra initarg :events to the generic-html-input
class, to which to you can pass a list of (eventname . javascript) lists,
for example '(("onchange" (call-js-function-1) (return true)) - the two
elements in the cdr will be put into the javascript lambda that is
registered for the event.

Anyway, I added the events slot here:

(defclass generic-html-input
(form-field)

  ((dom-id :accessor
dom-id

           :initarg
:dom-id

           :initform (js:gen-js-name-string :prefix
"_ucw_"))

   (client-value :accessor client-value :initarg
:client-value

                 :initform
""

                 :documentation "The string the client submitted along with
this field.")
   (name :accessor name :initarg :name :initform
nil)

   (tabindex :accessor tabindex :initarg :tabindex :initform
nil)

   (events :accessor events :initarg :events :initform
nil)))


And the first when clause in the render method is also new:


(defmethod render :after ((field
generic-html-input))

  (when (events
field)


(<ucw:script

     `(progn ,@(mapcar (lambda (x) `(dojo.event.connect

                                     (document.get-element-by-id ,(dom-id
field))
                                     ,(car
x)

                                     (lambda
(event)

                                       (progn ,@(cdr
x)))))

                       (events
field)))))

  (when (validators
field)


(<ucw:script

     `(setf (slot-value (document.get-element-by-id ,(dom-id field))
'ucw-validate)
            (lambda
()


,@(loop

                   for validator in (validators
field)

                   collect (generate-javascript field
validator))))

     `(dojo.event.connect

       (document.get-element-by-id ,(dom-id
field))


"onkeyup"

       (lambda
(event)

         ((slot-value (document.get-element-by-id ,(dom-id field))
'ucw-validate))))
     (when (initially-validate
field)

       `((slot-value (document.get-element-by-id ,(dom-id field))
'ucw-validate))))))

Bye,
Marijn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20060607/a9961463/attachment.html>


More information about the bese-devel mailing list