Examples:
Default options:
<?php echo $form->create( 'Post' ); ?>
<?php $titles = array( 1 => 'Tom', 2 => 'Dick', 3 => 'Harry' ); ?>
<?php echo $form->input( 'title', array( 'options' => $titles ) ) ?>
<label for="nothing">This checkbox won't be send (and it won't trigger Ajax reqest)</label>
<input id="nothing" type="checkbox" name='data[Post][nothing]' value='1' />
</form>
<?php
echo $ajax->observeField( 'PostTitle',
array(
'url' => array( 'action' => 'edit' ),
'complete' => 'alert(request.responseText)'
)
);
?>
Comments
Post a comment
Additional options:
- $options['before'] - this options will be executed before sending Ajax request
- $options['after'] - this options will be executed after sending Ajax request
- $options['confirm'] - this options will be displayed in confirm window
- $options['condition'] - Ajax request will be created only if condition will return true
- $options['position'] - where responseText should be placed (posible values: html, text, append, prepend, after, before, wrap...)
- $options['with'] - string parameters that will passed to Ajax data option
- $options['form'] - id of form that will be serialized adn passed to Ajax data option
- $options['indicator'] - id of element that will be shown while browser is waiting form response from server
2010-10-12 19:47:26
I'm trying to use observeField, but I need the information of two fields of my Form, How can I use $option['with'] or/and $option['form'] or another option to obtain the information? Thank you very much, this is a very, very good helper.
Best Regards,
Edgar Muralles
Guatemala
2010-10-12 21:46:43
Hi Edgar,
I think that you should observe all fields in form by observeForm or use observeField two times.
2010-10-25 15:15:06
Hi,
When I use observeForm, have any whay to know in controller wich form element has changed?
2010-10-26 16:52:24
Hi Geidivan J.,
There isn't build in parameter that tells you which element was changed, but you can put defalts in session and check which filed was changed and update new values in session.
I think that is the best way to do your job without modifying helper.
2010-10-29 17:41:55
hi kvas,
Im using the above and specifying url to update.. is it possible to add effects to this and how?
thanks
2010-10-30 09:59:38
Hi smiler,
What kind of effects do you want to add?
2011-02-22 09:33:41
Hello kvas,
first thanks for your great helper...
could you please show an example of the 'position' option?
I have tried:
'position'=>'$("#responsediv")'
'position'=>'$("#responsediv").html()'
'position'=>'$("#responsediv").html(request.responseText)'
with no success. Obviously #responsediv exists in the page...
2011-02-22 16:20:31
hi Angel,
http://www.cakephp.bee.pl/ajax/link -> using position
2011-02-22 16:40:58
Thanks kvas, of course it's there.
2011-03-12 14:10:23
Hi Kvas, How can I do chained dropdown, ex if I have 3 models continents,countries, cities.
2011-03-14 08:49:02
Hi carlosb,
I think that you should do it in one request, and all data modifications should be done in one action.
2011-03-21 21:51:00
Hi Kvas,
I'm using observeField to trigger an ajax call from a dropdown list (ProjectsCategorySelect).
How do I send the value of the selected along with the controller call?
Here's my code:
echo $ajax->observeField( 'ProjectsCategorySelect',
array(
'url' => array('controller' => 'projects', 'action' => 'get_project_by_category', "$(\"#ProjectsCategorySelect\").val()" ),
'complete' => 'alert(request.responseText)'
) );
"$(\"#ProjectsCategorySelect\").val()" doesn't seem to work ...
Thx for your answer!
2011-03-22 18:28:39
Hi Thomas,
You shouldn't add value in url, it's already send in POST.
Try:
echo $ajax->observeField( 'ProjectsCategorySelect',
array(
'url' => array('controller' => 'projects', 'action' => 'get_project_by_category'),
'complete' => 'alert(request.responseText)'
) );
and check $this->data in controller
2011-04-18 22:25:56
Hi kvas,
I'm using the observefield to make something like autocomplete, except that the results wont appear as a dropdown list, but as a seperate table in a div-element.
However I'm trying to find a way that the observerfield checks after every key pressed instead of the standard onChange event.
Any suggestions?
Thanks!
2011-04-19 16:51:52
Hi Jerre,
In my helper it's not possible. But you can make new function in your helper (copy of observeFiled) and replace jquery 'change' method to 'keyup'. I think that this solution will make your job.
2011-04-19 19:42:39
Thanks, that solved my issue!
2011-05-27 10:11:06
Kvas... You're awesome!
2011-05-27 10:33:50
Kvas... You're awesome!
2011-06-11 18:30:29
Hi.
I am getting Fatal error: Call to a member function observeField() .
After changing the $ajax to $this->Ajax, I am getting Fatal error: Call to a member function event().
Please help.
2011-09-29 08:57:40
I have an autocomplete field which shows all the cities. When i select the city, the states should be populated. I am using observeField for this. When i use keyboard to select the city, it works, but does not work when i select the city using a mouse. Please help