Symfony
Symfony

Reputation: 2439

CHtml::link Confirm repeats Yii

FOUND THAT CStarRating is causing this error if it is removed it gets ok.Also CStarRating makes page render extremely slow plus it also causes other jquery plugins to malfunction

I have used confirmation inside a Jquery acordin. main tabs of acordin are Categories and in side there is Items. User can delete both Items and Categories(of course different tables and models).

Now when I click on delete category it asks should it delete or not .....Till now everything is fine but as long as I click cancel AND category has Items in its panel confirm repeats itself for number of items time. following is my code. Please help me out

Following Image will illustrate what I mean enter image description here Thanks

<?php
foreach($model->categories as $Category){
        echo  CHtml::link('<span id="add_new_item">Add New Item </span>', array('items/create','id'=>$Category->id));
        echo ' <span id="update_del_category">';
        $image = CHtml::image('/Hunt2Eat/assets/b4e73c2b/gridview/update_item.png', 'Update', array('class' => 'view'));
        echo  'Edit';
        echo  CHtml::link($image, array('category/update', 'id'=>$Category->id));
        $image = CHtml::image('/Hunt2Eat/assets/b4e73c2b/gridview/delete_item.png', 'Delete', array('class' => 'view'));
        echo  ' Delete';
        echo  CHtml::link($image,'#',array('submit'=>array('category/delete','id'=>$Category->id),'confirm' => 'Are you sure you want to delete '.$Category->name.'?'));

    echo  '</span>
          <ul style="width:99%;" id="menu3" class="menu noaccordion">
            <li style="width:100%; ">
                <a href="#" style="color:white; padding:6px 0 6px 5px;">'.$Category->name.'</a>
                    <ul style="width:99%">
                        <div id="item_headings">
                             <label id="item_name"> Name </label>
                             <label id="item_price"> Price (PKR)</label>
                             <label id="item_rating"> Rating </label>
                        </div>';

foreach($Category->items as $Item)
    {
    echo  '<div id="update_del_item">';
    echo   CHtml::link('Edit', array('items/update', 'id'=>$Item->id));
    echo  '</div>
                 <div id="update_del_item">';
    echo  CHtml::link('Delete','#',array('submit'=>array('items/delete','id'=>$Item->id),'confirm' => 'Are you sure?'));
    echo  '</div>
                <li >
                <a href="#" name="Item">
                    <div style="height:20px; width: 360px;">
                        <span id="item_list">'.$Item->name.'</span>
                        <span id="item_list">'.$Item->price.'</span>
                        <span style="float:right;">'.$this->renderPartial('_rating',array('model'=>$model),TRUE,TRUE).'</span>
                    </div>    
                </a>                
            </li>';
}//For Loop to Extract category Items from category Array
    echo 
           '</ul>
        </li>
     </ul>';
}//For Loop to Extract Categories from Hotel array

?>

Upvotes: 1

Views: 3231

Answers (1)

zuo
zuo

Reputation: 1091

I think the problem is from multiple event delegations of jquery. For

echo  CHtml::link('Delete','#',array('submit'=>array('items/delete','id'=>$Item->id),'confirm' => 'Are you sure?'));

Yii framework will give the anchor a unique id and register a piece of javascript(jquery) in html as:

jQuery('body').undelegate('#yt0', 'click').delegate('#yt0', 'click', function() {
    if (confirm('Are you sure?')) {
        jQuery.yii.submitForm(this, '/index.php/items/delete/4', {});
        return false;
    } else return false;
});

where yt0 is the unique id assigned. Usually there is no problem since it does undelegating first. Can you check the javascript registered by Yii?

Upvotes: 1

Related Questions