Skip to content

Skip Step Validation

Coackroach edited this page Jan 19, 2020 · 2 revisions

On many occasions we have a scenario where we have a related table attached to our main table where we can skip adding a related record or choose to add, for example user registration will involve the account details and profile but there can be an entity like Business Profile OR Books interested in with a hasMany relation but it isnt necessary that you add the Books or Business Profile, but if you do enter them you will have to go through the validation that depends on the validation rules in that model.

Previously yii2-formwizard extension would require the validation and wont let you go through the step if the model has any of the fields required, and failed in the above described situation.

With the introduction of the the new option isSkippable under the steps configuration then the widget will automatically detect if the user want to skip the whole step or not. It detects if there is any input that has any text or option selected then it wont by pass the step and will require you to enter the required fields for that step depending on the model rules and if you havent added any text in any of the inputs in that step then the widget would interpret that you want to skip the validation for the whole step, and it would let you navigate to the next step.

You just need to provide option as simple boolean true or false and the rest is done by the widget. You can use the option like below

use buttflattery\formwizard\FormWizard;
echo FormWizard::widget([
    'steps'=>[
        [
            'model'=>$userModel,
            'title'=>'User Info',
            'description'=>'Add you account details',
            'formInfoText'=>'Fill all fields'
        ],
        [
            'model'=> $businessProfile,
            'isSkipable'=>true
            'title'=>'My Business Profile.',
            'description'=>'Add your business profile details.',
            'formInfoText'=>'Fill all fields'
        ],
    ]
]);
Clone this wiki locally