<span class="gmail_quote"></span>(I got a bounce for this mail, so I'm re-sending it... if you're lucky you aren't getting it twice.)<br><div><div><br></div></div><br>--------- Forwarded message ----------<br><span class="gmail_quote">
From: <b class="gmail_sendername">Marijn Haverbeke</b> <<a href="mailto:marijnh@gmail.com">marijnh@gmail.com</a>><br>Date: Jun 7, 2006 2:58 PM<br>Subject: Events for input field objects<br>To: <a href="mailto:bese-devel@common-lisp.net">
bese-devel@common-lisp.net</a><br><br></span><div><div>Hey,<br><br>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?
<br><br>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.
<br><br>Anyway, I added the events slot here:<br><br>(defclass generic-html-input (form-field) <br> ((dom-id :accessor dom-id
<br> :initarg :dom-id <br> :initform (js:gen-js-name-string :prefix "_ucw_"))
<br> (client-value :accessor client-value :initarg :client-value <br> :initform ""
<br> :documentation "The string the client submitted along with this field.") <br> (name :accessor name :initarg :name :initform nil)
<br> (tabindex :accessor tabindex :initarg :tabindex :initform nil) <br> (events :accessor events :initarg :events :initform nil)))
<br><br>And the first when clause in the render method is also new:<br> <br>(defmethod render :after ((field generic-html-input))
<br> (when (events field) <br> (<ucw:script
<br> `(progn ,@(mapcar (lambda (x) `(dojo.event.connect <br> (document.get-element-by-id ,(dom-id field))
<br> ,(car x) <br> (lambda (event)
<br> (progn ,@(cdr x))))) <br> (events field)))))
<br> (when (validators field) <br> (<ucw:script
<br> `(setf (slot-value (document.get-element-by-id ,(dom-id field)) 'ucw-validate) <br> (lambda ()
<br> ,@(loop <br> for validator in (validators field)
<br> collect (generate-javascript field validator)))) <br> `(dojo.event.connect
<br> (document.get-element-by-id ,(dom-id field)) <br> "onkeyup"
<br> (lambda (event) <br> ((slot-value (document.get-element-by-id ,(dom-id field)) 'ucw-validate))))
<br> (when (initially-validate field) <br> `((slot-value (document.get-element-by-id ,(dom-id field)) 'ucw-validate))))))
<br><br>Bye,<br></div></div><div><span class="sg"><span>Marijn</span>
</span></div>