2014-02-10 95 views
0

我已經完成了一個yiibooster嚮導表單,一切正常,但是我想要強制客戶單擊一個TbExtendedGridView,然後才能執行下一步。yiibooster嚮導驗證

在窗體中有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的行客戶CLIK「下一步」將可以和他可以點擊「下一步」進入下一步。

非常感謝。

CODE TESTED工作:

$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); 
    });"); 
+0

您可以對這兩個腳本使用$ cs。 –

+0

是的我編輯它,我把這兩個腳本與CS,但第二個仍然是錯誤的 –

+0

這兩個JS代碼可以使用一個註冊語句註冊,無需編寫額外的代碼。選擇器可能不正確,因此它不起作用。 –

回答

0

你可以在jQuery中做到這一點。首先你必須設置Id爲TbExtendedGridView。下一步按鈕包含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'); 
} 
)"); 
?> 

如果這個工程,那麼整個代碼在此腳本複製。

+0

我想,此刻沒有結果:( –

+0

請發表您的代碼,美曾試圖發佈上述 –

+0