Yii Framework Forum: Dropdown List And Ajax - Yii Framework Forum

Jump to content

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

Dropdown List And Ajax It does not trigger ajax... Rate Topic: -----

#1 User is offline   jorge sequeira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 05-February 13

Posted 11 February 2013 - 06:33 PM

I have a dropdownlist that is supposed to update a textbox via ajax:

in my view form I have a table that goes like this:


  <table>

  <tr><th>Tipo</th><th>Descrição</th><th>Qtd.</th><th>Preço</th><th>Tx.Iva</th></tr>

      <tr>
      <td>
      
      
      <?php 
      
      echo CHtml::ajaxLink(
                 'Update text',
                 array('faturas/ES', 'cod' => 5), // <---- This one works fine
                 array('update' => '#teste')
           );
            
      echo CHtml::dropDownList('codservico1', '',$listaservicos,
            array( 
                   'ajax' => array(
                             'type'=>'POST',
                             'url' =>CController::createUrl('faturas/ES'), //<--This one never works. why?
                             'update'=>'#teste',
                             'data' => array('cod'=>5),
                  
                             ),
                   'empty' => 'Escolha o tipo',
                 ));            
      ?>
          
      <?php echo $form->error($model,'codservico1'); ?>

      </td>    

      <td><div id="teste"><?php echo CHtml::textField('servico1','',array('size'=>25)) ; ?></div></td>
      <td><?php echo CHtml::activeTextField($model,'quantidade1',array('size'=>5)); ?></td>
      <td><?php echo CHtml::activeTextField($model,'preco1',array('size'=>5)); ?></td>
      <td><?php echo CHtml::activeTextField($model,'taxiva1',array('size'=>5)); ?></td>
      </tr>


  </table>



The ajax link works fine, but when the user chooses some item from the dropdown... nothing happens...

I'm tired and probably making some stupid mistake... Can anyone help me?
0

#2 User is offline   tehmaestro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 11-February 13

Posted 12 February 2013 - 03:23 AM

Assing id 'teste' to the textfield.
So, change this
<td><div id="teste"><?php echo CHtml::textField('servico1','',array('size'=>25)) ; ?></div></td>

to this :
<td><div><?php echo CHtml::textField('servico1','',array('size'=>25, 'id' => 'teste')) ; ?></div></td>

0

#3 User is offline   jorge sequeira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 05-February 13

Posted 12 February 2013 - 04:22 AM

nope... nothing moves...
0

#4 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 313
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 12 February 2013 - 12:40 PM

Try changing this:

'url' =>CController::createUrl('faturas/ES'), //<--This one never works. why?


to this:

'url' =>Yii::app()->request->baseUrl. '/faturas/ES', // maybe wrong controller?


Also, keep the change mentioned in the post above. Previously you would have updated the content of the div rather than the text field.
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