Hi all,
I'm trying to add to the dropdown presentation the possibility to modify
the state of other fields on the same view, because I need to change
some dropdown selectable value list on the base of another dropdown
selected value.
I started to modify the sources of weblocks itself, in the hope to offer
something useful to the community but now I'm stuck with some lame
half-implementation.
I don't have a good understanding of the weblocks "internals", so,
before I continue wasting my time applying lame changes to weblocks, I
would like to have some suggestions from the wise members of the
community on how to proceed.
Just to give an idea of my approach I attached here my unfinished
changes.
I would like to know if there is a better approach (or more general,
since this functionality may be needed for almost all type of
presentation) or if I should continue the way I have chosen, and, in
this case, I'd like to have some suggestions on how to proceed :-)
Any help would be much appreciated.
Best regards,
Andrea.
--
Reclama i tuoi diritti digitali, elimina il DRM. Approfondisci su
http://www.no1984.org
Reclaim your digital rights, eliminate DRM. Learn more at
http://www.defectivebydesign.org/what_is_drm
--
You received this message because you are subscribed to the Google Groups
"weblocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/weblocks?hl=en.
diff -r 593ffca524d8 src/utils/html.lisp
--- a/src/utils/html.lisp Mon Jan 04 17:10:30 2010 +0100
+++ b/src/utils/html.lisp Mon Jan 11 18:02:20 2010 +0100
@@ -147,7 +147,7 @@
"A welcome message used by dropdowns as the first entry.")
(defun render-dropdown (name selections &key id class selected-value
- welcome-name multiple autosubmitp)
+ welcome-name multiple autosubmitp onchange)
"Renders a dropdown HTML element (select).
'name' - the name of html control. The name is attributized before
@@ -184,8 +184,12 @@
(:select :id id
:class class
:name (attributize-name name)
- :onchange (when autosubmitp
- "if(this.form.onsubmit) { this.form.onsubmit(); } else { this.form.submit(); }")
+ :onchange (cond (autosubmitp
+ "if(this.form.onsubmit) { this.form.onsubmit(); } else { this.form.submit(); }")
+ (onchange
+ (format nil "initiateActionWithArgs(\"~A\", \"~A\", this.value); return false;"
+ (make-action onchange) (session-name-string-pair)))
+ (t nil))
:multiple (when multiple "on" "off")
(mapc (lambda (i)
(if (member (princ-to-string (or (cdr i) (car i))) (ensure-list selected-value)
diff -r 593ffca524d8 src/views/types/presentations/dropdown.lisp
--- a/src/views/types/presentations/dropdown.lisp Mon Jan 04 17:10:30 2010 +0100
+++ b/src/views/types/presentations/dropdown.lisp Mon Jan 11 18:02:20 2010 +0100
@@ -15,7 +15,8 @@
the view field label.")
(autosubmitp :initarg :autosubmitp :accessor autosubmitp
:documentation "If bound, make the dropdown starts a
- submit action when the select item changes.")))
+ submit action when the select item changes.")
+ (onchange :accessor onchange :initarg :onchange)))
(defmethod render-view-field-value (value (presentation dropdown-presentation)
(field form-view-field) (view form-view) widget obj
@@ -24,20 +25,26 @@
(special *presentation-dom-id*))
(multiple-value-bind (intermediate-value intermediate-value-p)
(form-field-intermediate-value field intermediate-values)
- (render-dropdown (if field-info
- (attributize-view-field-name field-info)
- (attributize-name (view-field-slot-name field)))
- (obtain-presentation-choices presentation obj)
- :welcome-name (if value
- (if (form-view-field-required-p field)
- nil "None")
- (if (slot-boundp presentation 'welcome-name)
- (dropdown-presentation-welcome-name presentation)
- (view-field-label field)))
- :selected-value (if intermediate-value-p
- intermediate-value
- (when value
- (presentation-choices-default-value-key value)))
- :id *presentation-dom-id*
- :autosubmitp (if (slot-boundp presentation 'autosubmitp)
- (autosubmitp presentation)))))
+ (let ((onsubmit-func (when (slot-boundp presentation 'onchange)
+ (lambda (&rest args)
+ (funcall (onchange presentation)
+ value args presentation field
+ view widget obj)))))
+ (render-dropdown (if field-info
+ (attributize-view-field-name field-info)
+ (attributize-name (view-field-slot-name field)))
+ (obtain-presentation-choices presentation obj)
+ :welcome-name (if value
+ (if (form-view-field-required-p field)
+ nil "None")
+ (if (slot-boundp presentation 'welcome-name)
+ (dropdown-presentation-welcome-name presentation)
+ (view-field-label field)))
+ :selected-value (if intermediate-value-p
+ intermediate-value
+ (when value
+ (presentation-choices-default-value-key value)))
+ :id *presentation-dom-id*
+ :autosubmitp (if (slot-boundp presentation 'autosubmitp)
+ (autosubmitp presentation))
+ :onchange onsubmit-func))))