Set default values to form via Ajax handle
- JaxP
- Member | 62
Hello,
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
$this['accUnitForm']->setDefaults(array(
"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
- mikeb
- Member | 33
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.
HTH