【问题标题】:yiibooster wizard validationyiibooster 向导验证
【发布时间】: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


【解决方案1】:

您可以在 Jquery 中执行此操作。首先你必须设置TbExtendedGridView的ID。 Next Button 包含类 next 然后你就这样做

<script type="text/javascript">
window.onload=function(){
$('.next').attr('disabled',true);
}
$(document).ready(
function()
{
   $('.grid-view').click(function() 
{
   $('.next').attr('disabled',false);
});
}
);
</script>

我使用类作为选择器,但你可以使用使用 ID 作为选择器作为“#selector”。您还可以在 grid-view 的子元素上使用 jquery。以上只是一个例子。
以下是有关 jquery 选择器的一些信息
http://www.w3schools.com/jquery/jquery_ref_selectors.asp

编辑: 试试

   <?php $cs = Yii::app()->getClientScript();
$cs->registerScript('hello', "
$(window).load(function()
{ 
    alert('hello');
}
)");
?>

如果可行,则复制此脚本中的整个代码。

【讨论】:

  • 我正在尝试,目前没有结果:(
  • 请发布您尝试过的代码。在上面发布您有问题的代码
  • 它不起作用,警报不显示,向导表单无法正常工作:S
  • 现在它显示警报,但我试图把其余的功能没有结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 2018-11-06
  • 1970-01-01
相关资源
最近更新 更多