raoul2000 / yii2-workflow

A simple workflow engine for Yii2
BSD 3-Clause "New" or "Revised" License
171 stars 48 forks source link

validation when not changing status #44

Closed cornernote closed 7 years ago

cornernote commented 7 years ago
    public function rules()
    {
        return [
            [['status'],raoul2000\workflow\validation\WorkflowValidator::className()],
            [['published_date'],'required',
                'on' => 'enter status {post/published}'],
        ];
    }

When I change to status=published I require published_date.

However once it's in published, there is no validation unless the status changes again.

It would be nice if I could say published_date was required if status=published (or if the status is in a given list). Is there any easy way to do this without making a custom validator?

raoul2000 commented 7 years ago

Hi @cornernote, as you have understood, the WorkflowValidator validator only perform validation on status change and right now, only a custom validator could do what you describe

cornernote commented 7 years ago

Can we add another state that checks the current status instead of a transition?

raoul2000 commented 7 years ago

yes that's an option. Another option could be to create a reflexive transition from {post/published} ot itself. This way, when the model is saved and the status does not change, yii2-workflow will assume it is dealing this transition and perform configured validation.

That could work ....