beastbytes / yii2-wizard

Yii2 Extension to handle multi-part form wizards
Other
37 stars 21 forks source link

Bug when using conditional validation #8

Open rtwent opened 8 years ago

rtwent commented 8 years ago

When step model has conditional validation callback function (https://github.com/yiisoft/yii2/blob/master/docs/guide/input-validation.md#user-content-conditional-validation-) the wizard end() its work and redirect to invalidStep.

BenasPaulikas commented 8 years ago

I can confirm this bug. Any ideas why ?

BenasPaulikas commented 8 years ago

@rtwent We can't save functions into session :(,

In your controlle do:

  $model['_validators'] = [];
  $event->data = $model;
rtwent commented 8 years ago

@BenasPaulikas I decided this issue by using custom validators (http://www.yiiframework.com/doc-2.0/guide-input-validation.html#creating-validators). They work perfect. Yes, the problem that it is impossible to save lambda function in session http://stackoverflow.com/questions/16788049/storing-function-in-session-variable

pritipal7791 commented 8 years ago

same problem like mention above .Please provide a solution for it.

IvanMakarenko commented 6 years ago

I use simple DTO model for save data. My method of getting model for current step:

    /**
     * Return form model for current step. Get it from WizardBehavior (session) or create new.
     *
     * @uses forms (AllocationSectionForm, CompanyInfoForm, GoodsInfoForm) from core\forms\partner\signup\
     * @return Model
     */
    private function getWizardModel($event)
    {
        $modelName = 'core\\forms\\partner\\signup\\' . ucfirst($event->step);
        if (empty($event->stepData)) {
            return new $modelName();
        }

        $model = new $modelName();
        $model->setAttributes($event->stepData->attributes(), false);
        return $model;
    }