Yii 1.1: efilterwidget

form widget, enable users to select values obtained from a remote ajax query
1 follower

EFilterWidget

author: Christian Salazar christiansalazarh@gmail.com

licence: NEW BSD

Links:

Wiki en Español

EFilterWidget GIT Repository

screenshot

EN

This widget presents a form containing a set of fields defined on the widget arguments, when user press the 'Find' button an ajax action will be fired, in response the client must select an option obtained from your remote query. When user press "OK" the onSuccess event will be fired receiving the selected argument from the dropDownList option and the input field with ID referenced by the widget attribute 'receptorId' will be set to the selected value.

ES

Este widget presenta un formulario al cliente, el cual dispara una consulta ajax con los parametros configurados, devolviendo al cliente una lista de opciones para seleccionar cuando este presiona el boton "Buscar"(Find). Cuando el usuario presiona el boton "OK" ocurren dos cosas: Se lanza el evento onSuccess el cual recibe como argumento la opcion seleccionada en el dropDownList y además el inputField con el ID establecido en el atributo del widget 'receptorId' sera establecido con el valor seleccionado.

Example Widget:

<?php                                                                          
    $this->widget('ext.efilterwidget.EFilterWidget'
    ,array(
        'id'=>'efilterwidget1',
        'findButtonLabel'=>'Find>>',
        'okButtonLabel'=>'OK',
        'fields'=>array(
            'year'=>array(
                    'ui'=>'text',
                    'label'=>'Year:',
                    'value'=>'',
                    'size'=>10,
                ),
            'month'=>array(
                    'ui'=>'list',
                    'label'=>'Months:',
                    'value'=>'FEB',
                    'size'=>10,
                    'options'=>array(''=>'??','JAN'=>'Enero','FEB'=>'Febrero'),
                ),
        ),

        //  use this attribute to pass any data readed from your Form.
        //  suppose you have $form->textField($model,'anyattribute');
        //  containing a value to be passed back to your action in order
        //  to perform a search.
        //
        //  in your action this value is passed via 'arg' attribute name
        //  $_GET['arg']  
        //
        'actionInputArgumentID'=>'Form_anyattribute',

        'action'=>array('site/efilterwidgetsample'),

        // when user press OK, the inputField using this ID will be setted 
        // to the selected value
        'receptorId'=>'testValue',
        // when user press OK, this event will be fired. data is the selected
        // options taken from the dropDownList.
        'onSuccess'=>"function(data){ $('#logger').html(data); }",

        'onError'=>"function(err){ $('#logger').html('error: '+err);  }",
        'backgroundColor'=>'#ccffee',
    ));
?>  
<div id='logger'></div>
<?php 
    echo "Example text field receptor:";
    echo CHtml::textField('testValue','');
?>

Your Action:

<?php
// in any controller, please be consistent with 'action' parameter on widget.
//
public function actionEFilterWidgetSample(){
    // 'keys' is an argument sent by EFilterWidget who informs about
    //  each key present in URL argument. is a helper.
    //  is a comma-separated key names string.  
    $keys = explode(",",$_GET['keys']);

    // a value readed from your form referenced by: 'actionInputArgumentID'
    $anyValue = $_GET['arg'];

    // sample array filtered by argument passed by URL
    //  example:  
    //  Person::model()->findByAttributes(array('uid'=>$_GET['uid']));
    //  available keys: $_GET['keys'], will return: "uid,firstname" (ie). 
    $sample = array(
         array('userid'=>'U1', 'name'=>'christian')
        ,array('userid'=>'U2', 'name'=>'anahi')
        ,array('userid'=>'U3', 'name'=>'pedro')
        ,array('userid'=>'U4', 'name'=>'lisbeth')
    );
    //  IMPORTANT:
    //  The widget requires JSON data
    //  please return a value generated by CHtml::listData
    //  and converted to json using: CJSON::encode(...)
    header("Content-type: application/json");
    echo CJSON::encode(CHtml::listData($sample, 'userid', 'name'));
}
?>

Be the first person to leave a comment

Please to leave your comment.

Create extension