问题
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