Yii Framework Forum: Using ajax to update another field - nothing in Post - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using ajax to update another field - nothing in Post Rate Topic: -----

#1 User is offline   amorangi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 01-May 09

Posted 01 November 2010 - 08:46 PM

I'm trying to use a dropDownList to update a text field. I'm using the following code:

<?php echo $form->dropDownList($lineitem,'stock_item_id',$stockItemListData,array(
                'ajax' => array(
                'type'=>'POST', //request type
                'url'=>CController::createUrl('invoiceHeader/dynamicDescription'), //url to call.
                //Style: CController::createUrl('currentController/methodToCall')
                'update'=>'#InvoiceItems_description', //selector to update
                //'data'=>'js:javascript statement' 
                //leave out the data key to pass all form values through
                )));  ?>


however nothing seems to be passed to the controller. I've looked through Firebug, which I'm using for the first time to try and figure out this issue, and as far as I can tell nothing is being passed in the Post. If I was to put something in the data part what would it be?

Can anyone tell me what I might be missing?
0

#2 User is offline   amorangi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 01-May 09

Posted 02 November 2010 - 12:15 AM

Ok, it's definitely not passing any data in the Post.

If I change the code to
<?php echo $form->dropDownList($lineitem,'stock_item_id',$stockItemListData,array(
                'ajax' => array(
                'type'=>'POST', //request type
                'url'=>CController::createUrl('invoiceHeader/dynamicDescription'), //url to call.
                //Style: CController::createUrl('currentController/methodToCall')
                'update'=>'#InvoiceItems_description', //selector to update
                'data'=>'InvoiceItems[stock_item_id]=8',
                //leave out the data key to pass all form values through
                )));  ?>

(hard coding in the data to pass) it works fine. Can anyone tell me what I need to add to get the value selected from the dropdown into the data? I'm no ajax expert at all.
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 02 November 2010 - 04:56 AM

This will work:
'data'=>'js:{"'.CHtml::activeName($lineitem, 'stock_item_id').'": $("#'.CHtml::activeId($lineitem, 'stock_item_id').'  option:selected" ).val()}',

1

#4 User is offline   amorangi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 01-May 09

Posted 02 November 2010 - 01:43 PM

View Postzaccaria, on 02 November 2010 - 04:56 AM, said:

This will work:
'data'=>'js:{"'.CHtml::activeName($lineitem, 'stock_item_id').'": $("#'.CHtml::activeId($lineitem, 'stock_item_id').'  option:selected" ).val()}',


Awesome, that works! Thanks
0

#5 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 03 November 2010 - 02:12 AM

Yeah!!

Just remember that Yii is a php framework, not a javascript one. Very often Yii works so awesome that seems like to do all javascript possible without actually writing a single line of js code, but sometimes no.

Remember that:

- property are escaped, so your js will be spoiled. In order to prevent Yii from distroy your beloved js, use the prefix 'js:', that explain to Yii to "attend to his own problems"
- All name and id are authomatically generated by Yii, you can use "CHtml::activeName" and "CHtml::activeId".

About jquery documentation, you can refer to jquery site but, unfortunately, this documentation is not as good as the Yii one... ask freely in the forum for hemp.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users