Closed myleshyson closed 2 years ago
Trying to add a validation rule to the CalendarModel. The rules function in that class doesn't call parent::rules(), so the EVENT_DEFINE_RULES event doesn't work like it should.
CalendarModel
parent::rules()
EVENT_DEFINE_RULES
Any chance you can update that function to look something like this?
public function rules(): array { $rules = parent::rules(); $rules[] = [ ['titleFormat'], 'required', 'when' => function (self $model) { return !$model->hasTitleField; } ]; $rules[] = [ ['titleLabel'], 'required', 'when' => function (self $model) { return $model->hasTitleField; } ]; return $rules; }
Or instead of using the rules method, maybe use the defineRules method?
protected function defineRules(): array { $rules = parent::defineRules(); $rules[] = [ ['titleFormat'], 'required', 'when' => function (self $model) { return !$model->hasTitleField; } ]; $rules[] = [ ['titleLabel'], 'required', 'when' => function (self $model) { return $model->hasTitleField; } ]; return $rules; }
defineRules seems to be how core craft models define their validation rulesets, I think so that people can extend if needed.
defineRules
This is now fixed in Calendar 3.13.13 and 4.0.0-beta.6. 🙂
Trying to add a validation rule to the
CalendarModel
. The rules function in that class doesn't callparent::rules()
, so theEVENT_DEFINE_RULES
event doesn't work like it should.Any chance you can update that function to look something like this?
Or instead of using the rules method, maybe use the defineRules method?
defineRules
seems to be how core craft models define their validation rulesets, I think so that people can extend if needed.