十月CMS设置了动态的datepicker Mindate



我需要动态设置

public function filterFields($fields, $context = null)
{
   $return_date = $fields->return_date->value;
   if(empty($return_date)) {
     $fields->return_date->minDate = Carbon::now();
   }
}

不起作用!

hmm,可以是 datetime widget是 setting this restrictions at init time,而 filterfields so so 它无法使用新的修改数据。

到Over come this 我们设置了INIT 之前设置配置数据,我们使用controller method formExtendFieldsBefore将此方法添加到您的controller

public function formExtendFieldsBefore($form) {
    $form->fields['return_date']['minDate'] = Carbon::now()->format('Y-m-d');
}

它应该有效,请检查一下,如果面对任何问题,请发表评论。

您应该注意型号的fields.yaml-您在哪里定义了return_date字段,是在主要还是辅助选项卡中?

尝试:

public function formExtendFieldsBefore( $widget ) {
    $widget->tabs['fields']['return_date']['minDate'] =  Carbon::now()->format('Y-m-d');
}

public function formExtendFieldsBefore( $widget ) {
    $widget->secondaryTabs['fields']['return_date']['minDate'] =  Carbon::now()->format('Y-m-d');
    // notice here $widget->secondaryTabs Vs $widget->tabs
}

这应该有效,如果不请共享您的fields.yaml文件。

最新更新