Tuesday, November 24, 2009

Re: CAKEPHP Country Region Combobox via AJAX

I want to filling up Casts combopbox from Religion combobox change
event.
Below is code for my View file.

<?php echo $javascript->link('prototype'); ?>
<tr>
<td class="tblheight"></td>
<td colspan="2" class="tblheight"></td>
</tr>
<?php
echo $form->input('religion_id');
echo $form->input('cast_id');
?>
<br />
<?php
$options = array('url' => 'getCast', 'update' => 'UserCastId');

echo $ajax->observeField('UserReligionId', $options);

echo $form->end();
?>

Below is my controller action

function getCast()
{


$this->set('options',
$this->User->Cast->find('list',
array('conditions' => array
('Cast.religion_id'=>$this->data['User']['religion_id']),'group' =>
array('Cast.name'))));
$this->render('/users/update_cast_select');
}

Belos is the update_cast_select result ctp file

<?php foreach($options AS $k=>$v) : ?>
<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
<?php endforeach; ?>

I am using 3 model right now as below.


CAST MODEL

<?php
/*
* Created on Oct 7, 2009
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class Cast extends AppModel
{
var $name = 'Cast';

var $BelongsTo = array('Religion','className' => 'Religion',
'foreignKey' => 'religion_id',
'conditions' => '',
'fields' => '',
'order' => '');

var $hasMany = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'cast_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);

}
?>


REligion Model

<?php
/*
* Created on Oct 7, 2009
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class Religion extends AppModel
{
var $name = 'Religion';
var $hasMany = array('Cast' => array(
'className' => 'Cast',
'foreignKey' => 'religion_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'User' => array(
'className' => 'User',
'foreignKey' => 'cast_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
) );
}
?>
and USER Model

<?php
/*
* Created on Sep 18, 2009
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class User extends AppModel
{
var $name = 'User';
// var $hasOne = 'Contact';
var $belongsTo = array(
'Religion' => array(
'className' => 'Religion',
'foreignKey' => 'religion_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Cast' => array(
'className' => 'Cast',
'foreignKey' => 'cast_id',
'conditions' => '',
'fields' => '',
'order' => ''
));


-------------------------------------

The problme is IE : when I change the religion combobox nothing is
heappening.

and in Mozilla : When I change the religin combobx I am finding out
query in Cast combobox.

Let me know if you required more details. Thanks a lot for your help.

On Nov 22, 11:02 am, Pedro Nascimento <pnascime...@gmail.com> wrote:
> It seems it works, would you mind sharing the code?
>
>
>
> On Thu, Nov 19, 2009 at 09:14, NRV <shahnir...@gmail.com> wrote:
> > Hi ALL,
>
> > I have implemented
>
> >http://www.croyantdebridiers.com/CakePHP_AJAX_selectbox_demo/ajaxcomb...
> > locally.
>
> > Its working fine at this moment live but on my local machine when I
> > change the combobox nothing happens. Can anybody help me out with the
> > same example.
>
> > Thank you
>
> > --
>
> > 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<cake-php%2Bunsubscribe@googlegroups.c­om>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=.- Hide quoted text -
>
> - Show quoted text -

--

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: