NewUser
NewUser

Reputation: 13333

place link inside dropdown list in Yii Framework

I have the dropdown list like this

   <?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'),
 array(
   'ajax'=> array(
             'type'=>'GET',
             'url'=>
             'data'=>
           ),
             'empty'=>--Select One---')); ?>

another link for creating a new customer is like this

 <?php echo CHtml::link('Create Customers', "",array(
        'style'=>'cursor: pointer; text-decoration: underline;',
        'onclick'=>"{addCustomers(); $('#dialogCustomers').dialog('open');}"));?>

I want the create customer link should come inside dropdown list.So how to place create customer link inside the dropdown list,how to merge the both links and create them into a single one?.Any help and suggestions will be highly appreciable.

Upvotes: 1

Views: 2553

Answers (2)

FSShaikh
FSShaikh

Reputation: 125

If I understand your requirement. you want to add links on the options of the drop down list. This is simple way to do this.

                    <?php 
                      echo CHtml::dropDownList('city_name', null,
                        $arrPopularCities, 
                        array(
                            'prompt' => 'Popular City',
                            'class' => 'btn btn-default btn-dropdown dropdown-toggle',
                            'style' => 'border-right:2px solid #4bacc6;',
                        )); 
                ?>

add bellow jquery

    $('#city_name').change(function() {
    if($(this).val() != ""){
        window.location.assign('<?php echo Yii::app()->createUrl('city/view'); ?>' + '?id=' + $(this).val());
    }
});

Upvotes: 0

Johnatan
Johnatan

Reputation: 1268

Tbh i'm not really sure what you're trying to do, but from what i got you need something like this:

echo $form->dropDownList(
    $customers,
    'customer_name',
    CMap::mergeArray(
        CHtml::listData(
            Customers::model()->findAll(), 'id', 'customer_name'
        ),
        array(
            'create_customer_link'=>'Create new customer'
        )
    ),
    array(
        'empty'=>array('Select'=>'--Select One---'),
        'id'=>'Customers_name',
        'ajax'=> array(
            'type'=>'GET',
            'beforeSend'=>'js:function(){
                if($("#Customers_name").val() == "create_customer_link") {
                    addCustomers();
                    $("#dialogCustomers").dialog("open");
                    return false;
                }
            }',
            'url'=>...
            'data'=>...
        ),
        'options'=>array(
            'create_customer_link' => array('class'=>'my_custom_css_class'),
            // ... etc. You can add any html option here.
            // check http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail for more info
        )
    )
);

Upvotes: 1

Related Questions