How to correctly redraw form snippet after AJAX submit (fixed)

2 years ago

mskocik
Member | 7
+
0
-

Hi, I have a component consisting of 2 snippets:

  • data table
  • insert/edit form (control form in template)

When I insert new record, the form snippet is redrawn with values previously submitted. How can I avoid that? I want empty form after submit.

class ExerciseEditor extends UI\Control
...
    public function createComponentForm()
    {
        $form = $this->factory->create();
        $form->onSuccess[] = [$this, 'processEditorForm'];
        return $form;
    }

    public function processEditorForm($form, $values)
    {
        //process form...
        $this->redrawControl('listArea');
        $this->redrawControl('formArea'); // how to redraw empty form? It redraws with submitted values

        //NON-ajax workaroud
        $this->redirect('this');
    }

Is redirecting the only solution?

Last edited by mskocik (2016-08-16 10:07)

2 years ago

jiri.pudil
Member | 833
+
+2
-

Just clear the values :)

$form->setValues([], TRUE);

2 years ago

mskocik
Member | 7
+
0
-

jiri.pudil wrote:

Just clear the values :)

$form->setValues([], TRUE);

Shame on me, thanks a lot!

2 years ago

martin.knor
Member | 23
+
+1
-

But why setValues is set as @internal? (v.2.4)