[英]Octobercms set dynamically datepicker minDate
我需要动态设置
public function filterFields($fields, $context = null)
{
$return_date = $fields->return_date->value;
if(empty($return_date)) {
$fields->return_date->minDate = Carbon::now();
}
}
不行!
嗯,可能是datetime
小部件在init
时间setting this restrictions
, 之后触发了 filterfields
,因此它不能使用新的修改后的数据 。
为了解决这个问题, 我们在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
文件,这应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.