[Catalyst] Http::Prototype

John Wang johncwang at gmail.com
Thu Nov 17 21:59:11 CET 2005


$prototype->observe_field(...) should do what you want. I would call
prototype directly from the TT template using [% c.prototype.observe_field(...)
%]

In the following example, 'selectA' is used to initate the XMLHttpRequest
and the result is put in 'selectA_result' which is then read and used by the
'complete' callback to set the selectIndex for 'selectB'.

-----BEGIN TT2 Template snippet-----
<div id="selectA_result" style="display:none"></div>

<select id="selectA">
<option value="0">[ Select A ]</option>
<option value="1">A1</option>
<option value="2">A2</option>
</select>

<select id="selectB">
<option>[ Select B ]</option>
<option>B1</option>
<option>B2</option>
</select>

[% c.prototype.observe_field('selectA',{
url => '/ajax/doAction',
with => "'action='+document.getElementById('selectA').value",
update => 'selectA_result',
complete => "document.getElementById('selectB').selectedIndex =
document.getElementById('selectA_result').innerHTML"
}) %]
-----END TT2 Template snippet-----

-----BEGIN Controller snippet-----
sub doAction : Local {
my ($self,$c) = @_;
$c->res->output($c->request->param('action'));
}
-----END Controller snippet-----

HTH

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20051117/bbeca28e/attachment.htm


More information about the Catalyst mailing list