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

Notice: This thread is very old.
mskocik
Member | 53
+
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)

jiri.pudil
Nette Blogger | 1028
+
+2
-

Just clear the values :)

$form->setValues([], TRUE);
mskocik
Member | 53
+
0
-

jiri.pudil wrote:

Just clear the values :)

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

Shame on me, thanks a lot!

martin.knor
Member | 17
+
+1
-

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