我需要动态设置
public function filterFields($fields, $context = null)
{
$return_date = $fields->return_date->value;
if(empty($return_date)) {
$fields->return_date->minDate = Carbon::now();
}
}不是工作!
发布于 2018-02-06 01:16:49
嗯,可能是datetime小部件在init时间是setting this restrictions,而filterfields是在该之后触发的,所以它不能使用新的修改后的数据。
为了克服这个,我们在初始化之前设置配置数据,我们使用controller method formExtendFieldsBefore将这个方法添加到你的controller中
public function formExtendFieldsBefore($form) {
$form->fields['return_date']['minDate'] = \Carbon::now()->format('Y-m-d');
}它应该可以工作,请检查这个,如果遇到任何问题,请发表意见。
发布于 2018-02-07 01:53:22
您应该注意模型的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文件。
https://stackoverflow.com/questions/48627695
复制相似问题