如何在beforesave中调用CJuiDialog

时间:2013-09-11 08:06:04

标签: yii

如果有人能帮我找到解决问题的方法,我会很感激,我的创建表单中有一个复选框。如果我按下创建按钮,我想要一个弹出窗口,如果选中该复选框,如果取消选中该复选框,则不执行任何操作。

我在_form中的代码

<?php echo $form->checkBoxRow($model, 'default'); ?>

<div class="form-actions">
    <?php $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType'=>'submit',
        'type'=>'primary',
        'label'=>$model->isNewRecord ? 'Create' : 'Save',
    )); ?>
</div>

在我的创建控制器

public function actionCreate()
{
    $model=new EmpSched;

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['EmpSched']))
    {
        $model->attributes=$_POST['EmpSched'];
        if($model->save())
        $this->redirect(array('view','id'=>$model->id_empsched));
    }

    $this->render('create',array(
        'model'=>$model,
        'emp'=> new CActiveDataProvider('schedule'),
    ));
}

在我的create.php中

<?php
$this->breadcrumbs=array(
'Emp Scheds'=>array('index'),
'Create',
);

$this->menu=array(
array('label'=>'List EmpSched','url'=>array('index')),
array('label'=>'Manage EmpSched','url'=>array('admin')),
);
?>

<h1>Create EmpSched</h1>

<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>

<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'schedule-grid',
'dataProvider'=>$emp,
'columns'=>array(
    'id_sched',
    'sched_name',
    array(
      'name'=>'mon',
      'value'=>'$data->fkidday->monday->name'
    ),
    array(
        'name'=>'tues',
        'value'=>'$data->fkidday->tuesday->name'
    ),
    array(
        'name'=>'wed',
        'value'=>'$data->fkidday->wednesday->name'
    ),
    array(
        'name'=>'thurs',
        'value'=>'$data->fkidday->thursday->name'
    ),
    array(
        'name'=>'fri',
        'value'=>'$data->fkidday->friday->name'
    ),
    /*'sat',
    'sun',
    */
),
));
?>
<script>
$(function() {

    // when row is clicked
    $('#schedule-grid tbody:first').on('click', 'tr', function() {

        // get the ID
        var id = $(this).find('td:first').text();

        // select the same option in dropdown list with same value
        $('#EmpSched_fk_id_sched')
            .find("option[value="+ id +"]")
            .prop("selected", "selected");
    });
});
</script>

1 个答案:

答案 0 :(得分:0)

添加自定义javascript(假设创建按钮将提交表单)

$('#form-id').submit(function() {
    if $(this).find('#check-box-id').is(':checked') {
        // open popup here
    }

    return false;
});