Set default values to form via Ajax handle

Notice: This thread is very old.
Member | 62

I am trying to set default values to the form via ajax handle function.

I have something like this

public function handleGetUnitData($uid) {
    //accUnitForm is my form
        "name" => "default name"
    $this->redrawControl('unitManager'); //unitManager is snippet where is form included

Snippet UnitManager is being updated (by redrawControl) but default values are not set (network console doesn't give any error – everything just goes fine).

Any ideas how to load default values “onclick” to the form?
Thank you

Member | 13

Hi, problem is, that you try to set default values which is already rendered. I think what you need, is not to set default values but Values. I know that is not so clear solution, but try

        "name" => "default name"
    ), true);
Member | 30

i'm adding a note for the next person struggling with this.
if you look at the code for setDefaultValue the value is only set if the form is not submitted ($form->isSubmitted() ==false). (also the form must not be disabled or anchored). else no value is set.

However isSubmitted() will return true when there is any getHttpData – ie even when another form on the page has ajaxed or posted.

so if the another (even non-nette) form has ajaxed/posted then setDefaultValues won't set your values. instead use setValues. like wohral's post above says. This behaviour may be documented somewhere but i haven't see it.