【发布时间】:2014-02-10 13:00:06
【问题描述】:
我已经完成了一个 yiibooster 向导表单,一切正常,但我想强制客户在执行下一步之前单击 TbExtendedGridView。
表单中有 2 个 TbExtendedGridView 和 2 个日期字段。
下面是一些形式的代码:
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'zf-contratos-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'htmlOptions'=>array('class'=>'well'),
'action' => array( '/ZfContratos/create' ),
)); ?>
<div id="wizard-bar" class="progress progress-striped active">
<div class="bar"></div>
</div>
<?php $this->widget(
'bootstrap.widgets.TbWizard',
array(
'type' => 'tabs', // 'tabs' or 'pills'
'pagerContent' => '<div style="float:right">
<input type="button" class="btn button-next" name="next" value="Siguiente" />
</div>
<div style="float:left">
<input type="button" class="btn button-previous" name="previous" value="Atrás" />
</div>
<br /><br />',
'options' => array(
'nextSelector' => '.button-next',
'previousSelector' => '.button-previous',
'onTabShow' => 'js:function(tab, navigation, index) {
var $total = navigation.find("li").length;
var $current = index+1;
var $percent = ($current/$total) * 100;
$("#wizard-bar > .bar").css({width:$percent+"%"});
}',
'onTabClick' => 'js:function(tab, navigation, index) {alert("Tab Click Disabled");return false;}',
),
'tabs' => array(
array(
'label' => 'Arrendatarios',
'content' => $this->renderPartial('//ZfContratos/_form_arrendatarios', array('model' => $model, 'form' => $form), true),
'active' => true
),
array('label' => 'Inmuebles', 'content' => $this->renderPartial('//ZfContratos/_form_inmuebles', array('model' => $model, 'form' => $form), true)),
array('label' => 'Fecha', 'content' => $this->renderPartial('//ZfContratos/_form_contratos', array('model' => $model, 'form' => $form), true)),
),
)
); ?>
<?php $this->endWidget(); ?>
程序是,第一步禁用“下一步”,当客户单击 TbExtendedGridView 的一行时,“下一步”将可用,他可以单击“下一步”进行下一步。
非常感谢。
代码测试工作:
$cs = Yii::app()->getClientScript();
$cs->registerScript('hello', "
$(window).load(function()
{
alert('hello');
$('#next').attr('disabled',true);
});");
$cs->registerScript('button',"
$('#arrendatario').click(function()
{
$('#next').attr('disabled',false);
});");
【问题讨论】:
-
这两个脚本都可以使用 $cs。
-
是的,我编辑了它,我把两个脚本都放在了 cs 中,但是第二个仍然是错误的
-
两个js代码都可以用一个register语句注册,不需要额外写代码。选择器可能不正确,所以它不起作用。
-
完成! $cs->registerScript('button'," $('#arrendatario').click(function() { $('#next').attr('disabled',false); }); ");跨度>
-
不需要 document.ready :D
标签: javascript jquery yii widget yii-booster