Friday, May 29, 2009

radio buttons and observeField

Hi everybody,

I was just wondering if any has come across this or knows what i might
be doing wrong.

the problem:
I have a couple of radio buttons, i am observing these radio buttons
with ajax observeField. When clicked the radio buttons update a div
which has a select box in it. I have another observeField on the
select box that will update another select box. All of this works
fine. Except for one small thing with the radio buttons. They only
set the XHR request once. So after i use them once, nothing updates.

here is the code i use, maybe some one could give em some pointers or
see something i don't. Maybe it's not even the code it's just
something that happens with the radio buttons.

[code]
/*** within the Reservation_sites/add.ctp view ***/

<!-- table of radio buttons, probably not the
best way to do this, but it's just a test -->
<table cellpadding="0" cellspacing="0">
<tr>
<td class="radioSeparation">
<?php
echo $form->radio('ReservationSiteOptions.findByRegion', array(__
('Region', true), __('Province', true)), array('legend' => false,
'separator' => '</td><td class="radioSeparation">'));
?>
</td>
</tr>
</table>
<!-- the div to be updated -->
<div id="category">
</div>
<?php
$optCat = array('url' => 'update_category', 'update' => 'category');
//checking the source file showed me the ids of the radio buttons.
echo $ajax->observeField('ReservationSiteOptionsFindByRegion0',
$optCat);
echo $ajax->observeField('ReservationSiteOptionsFindByRegion1',
$optCat);
?>

/*** function of update_category in reservation_sites controller ***/
function update_category()
{
Configure::write('debug', 0);
$frenchFlag = $this->_getCurrentLang(); // used for dynamic setting
of DB data in proper language.
$name = 'region_id';
$id = $this->data['ReservationSiteOptions']['findByRegion'];
if($id == 0) {
//region selected.
if($frenchFlag == true) {
$category = $this->Region->find('list', array('fields' => array
('Region.id', 'Region.nom')));
} else {
$category = $this->Region->find('list', array('fields' => array
('Region.id', 'Region.name')));
}
$name = 'region_id';
} else {
//province selected.
if($frenchFlag == true) {
$category = $this->Province->find('list', array('fields' => array
('Province.id', 'Province.nom')));
} else {
$category = $this->Province->find('list', array('fields' => array
('Province.id', 'Province.name')));
}
$name = 'province_id';
$this->log($category);
}
$this->set(compact('category', 'name'));
}

/*** within the Reservation_sites/update_category.ctp view **/
<?php
if(!empty($category)) {
echo $form->select('ReservationSiteOptions.'.$name, $category, null,
array('id' => 'categoryList'));
} else {
__('There are no buildings in this region or province.');
}
echo $form->select('ReservationSiteOptions.building_id', array(),
null, array('id' => 'buildings'));
$options = array('url' => 'update_select', 'update' => 'buildings');
echo $ajax->observeField('categoryList', $options);
?>
[/code]

All other things are for the 2nd select box but there are no problems
with that section so i did not include it.

Thank you for those who take the time to help. See you guys later.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: