Domanda

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);
È stato utile?

Soluzione

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');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top