Skip to content

Edit Mode

Coackroach edited this page Jan 20, 2020 · 5 revisions

If you are using the formwizard for editing your data you will feel uneasy as the information is already filled in and you have to navigate through each and every step to change any information in the last step because the anchor links are not clickable keeping in mind the insertion mode where we need to validate the required step fields before moving on to the next, which isnt the case when editing as the information is already validated and saved and we should be able to jump to any step to change any info and the new data would be validated right away. so we can use the option editMode which takes a simple boolean and the rest is done by the widget. When the option is true the anchor links are activated and you can click the anchor/ step title to jump to the step.

If you have edit mode enabled and all steps all empty, if you jump to last step and try to submit the form clicking Finish button, it will highlight all steps that have errors and navigate you to the first error step.

If you use the formWizard for adding and editing a simple way would be to pass a var which holds true in actionUpdate() and false in actionCreate() and pass to the view.

public function actionUpdate($id)
{
    $model = $this->findModel($id);
    return $this->render('update', ['editMode' => true, 'model' => $model]);
}

View

echo FormWizard::widget([
    'wizardContainerId' => 'my-id',
    'editMode' => $editMode,
]);

You can see a demo here

Clone this wiki locally