Octobercms set dynamically datepicker minDate

六月ゝ 毕业季﹏ 提交于 2019-12-11 21:17:42

问题


I need to set dynamically

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

Not work!


回答1:


Hmm, may be datetime widget is setting this restrictions at init time and filterfields is fired after that so it can not use new modified data.

to over come this we set config data before init , we use controller method formExtendFieldsBefore add this method to your controller

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

it should work, please check this and if face any issue please comment.




回答2:


You should pay attention to your model's fields.yaml - Where have you defined the return_date field, is it in the primary or secondary tabs ?

Try :

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

Or

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

This should work, if it doesn't please share your fields.yaml file .



来源:https://stackoverflow.com/questions/48627695/octobercms-set-dynamically-datepicker-mindate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!