Yii Framework Forum: How to pass another field value to CjuiAutocomplete ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

How to pass another field value to CjuiAutocomplete ? Rate Topic: -----

#1 User is offline   Benn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 16-January 11
  • Location:Paris

Posted 29 January 2011 - 10:53 AM

Hello,
I'm trying to use CjuiAutocomplete widgets in replacement for dependant dropdownlists. (to select a brand, a model, and a version for a classifieds application)
here is my question :
my first autocomplete works well, it allows the user to select a brand.
My second one needs to display only models from the selected brand.
I figure I need to pass the brand_id to the autocomplete action through GET.
This can be done by passing an array to the widget :
$form->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'model'=>$model,
        'attribute'=>'model_id',
        'source'=>$this->createUrl('Ad/autocompleteModel', array('brand_id'=>"function() { $('#Ad_brand_id').val();}")),
        // additional javascript options for the autocomplete plugin
        'options'=>array(
                        'showAnim'=>'fold',
        ),


My problem is "function() { $('#Ad_brand_id').val();}" isn't interpreted as Javascript, but just as a string...
Any idea how I can get the field value of brand_id in there?

Thanks a lot!
Cheers

0

#2 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,448
  • Joined: 04-October 10

Posted 29 January 2011 - 01:10 PM

Use this instead http://www.yiiframew...e#source-detail

on 'source'=>'js:functionametocallthatwillhandlethecallwithbothvalues'

Will work
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#3 User is offline   Benn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 16-January 11
  • Location:Paris

Posted 29 January 2011 - 04:00 PM

Thanks for your quick answer :)
I'm sorry, I'm not quite sure how to get a javascript function to do what I need.
The brands, models, and versions lists are stored in the database.
How can I access it through the JS function?

[edit] : I've figured it out :) To anyone interested :


....
'source'=>'js: function(request, response) {
    $.ajax({
        url: "'.$this->createUrl('Ad/autocompleteModel').'",
        dataType: "json",
        data: {
            term: request.term,
            brand: $("#Ad_brand_id").val()
        },
        success: function (data) {
                response(data);
        }
    })
 }',
....

4

#4 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,448
  • Joined: 04-October 10

Posted 30 January 2011 - 07:07 AM

View PostBenn, on 29 January 2011 - 04:00 PM, said:

Thanks for your quick answer :)
I'm sorry, I'm not quite sure how to get a javascript function to do what I need.
The brands, models, and versions lists are stored in the database.
How can I access it through the JS function?

[edit] : I've figured it out :) To anyone interested :


....
'source'=>'js: function(request, response) {
    $.ajax({
        url: "'.$this->createUrl('Ad/autocompleteModel').'",
        dataType: "json",
        data: {
            term: request.term,
            brand: $("#Ad_brand_id").val()
        },
        success: function (data) {
                response(data);
        }
    })
 }',
....



Thanks for sharing
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#5 User is online   claudio.ferrari 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 23-November 11
  • Location:Brescia - Italy

Posted 18 January 2012 - 08:37 AM

Thank you so much !!!
claudio.ferrari@imagis.it
0

#6 User is offline   vario 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 03-January 10

Posted 22 March 2012 - 09:55 AM

Just wanted to say thanks for the solution Benn - much appreciated!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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