[Seaside] getting a single value through jQuery
Lukas Renggli
renggli at gmail.com
Tue Oct 6 12:31:57 UTC 2009
2009/10/6 Richard Durr <richard.durr at googlemail.com>:
> Hello,
> I'd like to set the background-color of a parent element that contains a
> selectbox using ajax without replacing the whole. I tried to load the value
> through "ajax html:" like so:
> html select
> onChange: (html jQuery ajax serialize: html jQuery this) ,
> ((html jQuery this parent: '.model' ) cssAt: 'background-color' put:
> (html jQuery ajax html: [:r | r text: 'red' ]));
> callback: [ :value | aModelObject color: value key. ];
> selected: selectedColor;
> addAll: colors;
> labels: [:item | item value.].
The use of
html jQuery this parent: '.model'
is a bit strange, because this only returns the *direct* parents that
have the class .model. You might easily end up with an empty result
set and simply nothing happens. It might not be a problem in your
case, but it would be more intention revealing if you used #closest:
instead of #parent:
The expression
html jQuery ajax html: [:r | r text: 'red' ]
does not return the requested value, but the AJAX object itself.
Furthermore AJAX calls are asynchronous, so they immediately return.
Something along the following lines should work:
(html jQuery this closest: '.model') cssAt: 'background-color' put: 'red'
If you want to go through a server round-trip you could integrate the
change into the AJAX call you do to serialize the value. What about
something along ...
html jQuery ajax
serialize: html jQuery this;
script: [ :script | script add: ((script jQuery: '.model')
cssAt: 'background-color' put: currentColor) ]
Cheers,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch
More information about the seaside
mailing list