1

I want to start out with, that im a noob to AJAX, jquery and that kinda stuff. But im currently working on a project, where i have a calender, where a substitute can specify if he is available a given day and the time period etc. Now im just struggling with the problem that then they click on a day, to specify that they are available, that i need a pop up window to show, where they can specify the time they are available. I have found several guides on Yii's forum on how to do it, the problem is though that the pop up window never opens.

Here is the code with the link specified, but when i check it on the homepage it says ../offer/calendar# <-- each link on a day links to the calendar not the pop up window

            $url = CHtml::ajaxLink(Yii::t('job', 'Ledig'), Yii::app()->createUrl('offer/createOffer'), array(
            'onclick' => '$("#offerDialog").dialog("open"); return false;',
            'update' => '#offerDialog'
                ), array('id' => 'showOfferDialog'));
        /** You can query the database for an entry for this day if you like or print out a message on each day.  Uncomment these two lines.  * */
        $this->calendar.= '<div class="' . $this->style . '-normal">'. $url . '</div><br/>';
        $this->calendar.= str_repeat('<p> </p>', 2);
CreamYGEEK
  • 175
  • 1
  • 1
  • 6

1 Answers1

0

The CHtml::ajaxLink method has the following signature: ajaxLink(string $text, mixed $url, array $ajaxOptions=array ( ), array $htmlOptions=array ( ))

The onclick event you're trying to bind to in this case is an HtmlOption and not an Ajax option hence, you need to specify it as such.

When you specify the onclick event to display your dialog, you also need to remove the return false; statement as this would prevent the ajaxCall from being made.

So your definition should look like this:

$url = CHtml::ajaxLink(
            Yii::t('job', 'Ledig'),
            Yii::app()->createUrl('leads/admin'),
            array('update' => '#offerDialog'),
            array('id' => 'showOfferDialog', 'onclick' => '$("#offerDialog").dialog("open");')
        );
//Show Link
echo $url;

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'offerDialog',
    // additional javascript options for the dialog plugin
    'options'=>array(
        'title'=>'Dialog box 1',
        'autoOpen'=>false,
    ),
));

echo 'dialog content here';

$this->endWidget('zii.widgets.jui.CJuiDialog');
  • Thanks for the reply .. I have tried what you said, but the result is still the same. The link is still redirecting me to, ../offer/calendar# – CreamYGEEK Jul 08 '13 at 19:30
  • If you're still getting redirected to another url, then you should check that jQuery is loaded. In my answer, without jQuery loaded or if there's a javascript error, you would always be redirected because the javascript code to prevent the default behaviour of the generated link would not be executed. – Oladapo Omonayajo Jul 24 '13 at 15:11
  • It works now .. Just needed to restart Netbeans .. Thanks alot! – CreamYGEEK Jul 31 '13 at 07:52