views:

344

answers:

2

Hi,

I am pretty new to the zend framework and the JQuery helper.

I have been playing around with the ajaxLink method, and was wondering if there's a way to adapt it to use it in a form. Let me explain:

I want to add an "onChange" attribute on a "select element" in a form. When the select element is changed, I would like to have an ajax call, similar to the ajaxLink method, that will call a controller action, and then update a part of my view, or even better, that would update a text input within my form.

Do I make sense? I know I could write some js myself to handle the action call, but since it's managed automatically in the ajaxLink method, I thought they might be a way to redirect the ajax call to the controller action "automatically"...

The thing is, with the ajaxlink method, you declare it in the view, not in the form, so I don't know how to add this to the select element of my form... Does anyone know how to do this? Or maybe it's possible with another ajax helper?

Any help will be appreciated!! :)

A: 

You can

-- extend Zend_Form_Select;

-- write your own decorator to attach some javascript to form element;

-- add 'attribs' => array('onchange' => 'alert("Hi");') to your form element definition;

but I do not see any sense in this, because it's not reusable. The most narural way for me is:

<?php echo $this->form; ?>
<?php $this->jQuery()->onLoadCaptureStart(); ?>
jQuery('#myselect').change(function() { alert('Hi'); });
<?php $this->jQuery()->onLoadCaptureEnd(); ?>
Vladimir
+1  A: 

check here

ulduz114
Yes! Thanks that's exactly what I was talking about!
Piero