Yii Framework Forum: ajax dropdown problem With Extension Echosen - Yii Framework Forum

Jump to content

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

ajax dropdown problem With Extension Echosen Rate Topic: -----

#1 User is offline   rafaelrs5648 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 235
  • Joined: 02-October 13
  • Location:Cuba

Posted 17 April 2017 - 05:46 PM

This great extension. i have a little problem, i cannot make it work for dynamic dropdownlist. As I can solve this problems?
I have in my BD a tabla Clientes and one I join related signatories to many for CodCliente, that the primary key in the tabla is Clientes and in the tabla firmantes I have the field IdCliente for the relation.

I have the controller function:

public function actionActualizarFirmantes() {
        $model = Clientes::model()->findByPk($_POST['idCodigo']);

        //To fill firmantes
        $data = CHtml::listData($model->firmantes, 'CI', 'Nombre');//I look for firmantes in the tabla here the CI and the names of the cliente selected in the tabla clientes
        $firmantes = "";
        foreach ($data as $value => $name)
                $firmantes .= CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);

        // return data (JSON formatted)
        echo CJSON::encode(array(
                'firmantes' => $firmantes
        ));
        }


In the form the extension EChosen I put her in this way:
<?php
                        $this->widget('ext.EChosen.EChosen', array(
                                'target' => 'select',
                                'useJQuery' => true,
                                'debug' => false,
                        ));
                        ?>

In the form: I have two dropDownList:

First dropDownList:

<td colspan="3" title="Select the cliente">
                        <?php echo $form->labelEx($model, 'Cliente'); ?>
                        <?php
                        echo $form->dropDownList($model, 'CodCliente', CHtml::listData(Clientes::model()->findAll(array('order' => 'Descripcion')), 'CodCliente', 'Descripcion'), array(
                                'ajax' => array(
                                'type' => 'POST',
                                'url' => CController::createUrl('datossal/actualizarFirmantes'),
                                'dataType' => 'json',
                                'data' => array('idCodigo' => 'js:this.value'),
                                'success' => 'function(data) {
                                $("#Datossal_CI").html(data.firmantes); 
                        }')
                                )
                        );
                        ?>
<?php echo $form->error($model, 'CodCliente'); ?>
        </td>


Second dropDownList, where the names of the people related with that selected cliente must be shown:

<td title="The authorized are  shown to sign invoices when selecting the customer">
   <?php echo $form->labelEx($model, 'CI'); ?> <?php echo $form->dropDownList($model, 'CI', array()); ?>
   <?php echo $form->error($model, 'CI'); ?>  
  </td>


I know that there must be options with the extension but I do not know them, I wait if somebody is experienced with this, I need to make the filter for the better the quest, I clarify with this.

I put some Imagery to show better here:

My first dropDownList with the filter made by the extension:

Posted Image
The image without updating second dropDownList ( Authorized Person ):

Posted Image

This third image is like appear the two dropDownList without the extension Echosen, but they are many clientes , which is why I make the filter:
Posted Image
0

#2 User is offline   rafaelrs5648 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 235
  • Joined: 02-October 13
  • Location:Cuba

Posted 02 May 2017 - 07:41 AM

View Postrafaelrosales, on 17 April 2017 - 05:46 PM, said:

This great extension. i have a little problem, i cannot make it work for dynamic dropdownlist. As I can solve this problems?
I have in my BD a tabla Clientes and one I join related signatories to many for CodCliente, that the primary key in the tabla is Clientes and in the tabla firmantes I have the field IdCliente for the relation.

I have the controller function:

public function actionActualizarFirmantes() {
        $model = Clientes::model()->findByPk($_POST['idCodigo']);

        //To fill firmantes
        $data = CHtml::listData($model->firmantes, 'CI', 'Nombre');//I look for firmantes in the tabla here the CI and the names of the cliente selected in the tabla clientes
        $firmantes = "";
        foreach ($data as $value => $name)
                $firmantes .= CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);

        // return data (JSON formatted)
        echo CJSON::encode(array(
                'firmantes' => $firmantes
        ));
        }


In the form the extension EChosen I put her in this way:
<?php
                        $this->widget('ext.EChosen.EChosen', array(
                                'target' => 'select',
                                'useJQuery' => true,
                                'debug' => false,
                        ));
                        ?>

In the form: I have two dropDownList:

First dropDownList:

<td colspan="3" title="Select the cliente">
                        <?php echo $form->labelEx($model, 'Cliente'); ?>
                        <?php
                        echo $form->dropDownList($model, 'CodCliente', CHtml::listData(Clientes::model()->findAll(array('order' => 'Descripcion')), 'CodCliente', 'Descripcion'), array(
                                'ajax' => array(
                                'type' => 'POST',
                                'url' => CController::createUrl('datossal/actualizarFirmantes'),
                                'dataType' => 'json',
                                'data' => array('idCodigo' => 'js:this.value'),
                                'success' => 'function(data) {
                                $("#Datossal_CI").html(data.firmantes); 
                        }')
                                )
                        );
                        ?>
<?php echo $form->error($model, 'CodCliente'); ?>
        </td>


Second dropDownList, where the names of the people related with that selected cliente must be shown:

<td title="The authorized are  shown to sign invoices when selecting the customer">
   <?php echo $form->labelEx($model, 'CI'); ?> <?php echo $form->dropDownList($model, 'CI', array()); ?>
   <?php echo $form->error($model, 'CI'); ?>  
  </td>


I know that there must be options with the extension but I do not know them, I wait if somebody is experienced with this, I need to make the filter for the better the quest, I clarify with this.

I put some Imagery to show better here:

My first dropDownList with the filter made by the extension:

Posted Image
The image without updating second dropDownList ( Authorized Person ):

Posted Image

This third image is like appear the two dropDownList without the extension Echosen, but they are many clientes , which is why I make the filter:
Posted Image


Already this resolved into other after in the forum in Spanish
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