duanpu1963
2017-11-16 21:19
浏览 68
已采纳

Yii2 - 如果日历已打开,则停止字段验证

I have a Yii2 active form which includes a field with datepicker. My form is using following attributes:

<?php $form = ActiveForm::begin([
            'id' => 'campaign-form',
            'enableClientValidation' => true,
            'fieldConfig' => [
                'options' => ['class' => 'gg-create-group'],
                'labelOptions' => ['class' => null],
            ],
            'options' => [
                'autocomplete' => 'off',
                'enctype' => 'multipart/form-data',
            ],
        ]);
        ?>

I have a field using jquery datepicker, the issue is each time I click on the arrows to navigate through the months in the calendar, client validation is triggered an a error is shown:

enter image description here

I need to stop the error message if the calendar is open and I am using the calendar navigation.

I know I can turn off client validation using:

enableClientValidation => false

But I want to keep client validation. I am wondering if Yii javascript script: $yiiform has an option to do that?

图片转代码服务由CSDN问答提供 功能建议

我有一个Yii2活动表单,其中包含一个带有datepicker的字段。 我的表单使用以下属性:

 &lt;?php $ form = ActiveForm :: begin([
'id'=&gt;'campaign-form',
  'enableClientValidation'=&gt; true,
'fieldConfig'=&gt; [
'选项'=&gt; ['class'=&gt;'gg-create-group'],
'labelOptions'=&gt; [  'class'=&gt; null],
 
,
'选项'=&gt; [
'自动完成'=&gt;'关闭',
'enctype'=&gt;'multipart / form-data',  
],
]); 
?&gt; 
   
 
 

我有一个使用jquery datepicker的字段,问题是我每次点击箭头到 浏览日历中的月份,触发客户端验证并显示错误:

< 如果日历打开并且我正在使用,我需要停止错误消息 日历导航。

我知道我可以使用以下方式关闭客户端验证:

  enableClientValidation =&gt;  false 
   
 
 

但我想保留客户端验证。 我想知道是否Yii javascript脚本:$ yiiform有选项可以做到吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dousi1906 2017-12-05 17:07
    已采纳

    I found a solution. I can use validationOnBlur, if I set it to false on specific field it fixes the issue.

    <?php echo $form->field($model, 'client_end_date', 
    ['validateOnBlur' => false])->textInput(['readonly' => 'readonly']); ?>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题