ajax multiselect zavisly na selecte

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
majermi3
Člen | 2
+
0
-

Ahoj,

potreboval by som pomoct s nefunkcnym ajaxovym formularom. Ajax v podstate funguje a komponenta sa prekresli avsak po odoslani formularu sa posle prazde pole multiselectu.

public function renderConnect(){
        $this->template->_form = $this->template->form = $this['connection'];
    }

public function createComponentConnection($name) {
        $form = new Form;

        $partners = \db\Partner::getDistinct("partner_id", "code");
        $products = \db\Product::getDistinct("product_id", "name");

        $parameters = \db\ProductParam::getAll(null, null, array("product_id" => \db\Product::getAll()->getFirst()->product_id, "required" => 0))->getDistinct("idp", "fk_param_name");

        $form->addSelect("partner", "Partner", $partners);
        $form->addSelect("product", "Produkt", $products);

        $form->addMultiSelect("parameters", "Parametre", $parameters);

        $form->addSubmit('submit', 'Přidat');
        $form->onSuccess[] = $this->makeConnection;
        return $form;
    }

public function makeConnection(Form $form){
        $values = $form->getValues();
        \Nette\Diagnostics\Debugger::barDump($values, "connection values");
    }

public function handleChange($product_id){
        if($this->isAjax()){
            $parameters = \db\ProductParam::getAll(null, null, array("product_id" => $product_id, "required" => 0))->getDistinct("idp", "fk_param_name");

            $form = $this->getComponent("connection");
            $form['parameters']->setItems($parameters);

            $this->invalidateControl();
        }
    }

js v layoute

<script language="JavaScript" type="text/javascript" src="{$basePath}/js/jquery.js"></script>

        <script language="JavaScript" type="text/javascript" src="{$basePath}/js/netteForms.js"></script>
        <script language="JavaScript" type="text/javascript" src="{$basePath}/js/nette.ajax.js"></script>
        <script language="JavaScript" type="text/javascript" src="{$basePath}/js/jquery.nette.js"></script>
        <script language="JavaScript" type="text/javascript" src="{$basePath}/js/js.js"></script>

sablona

{form connection}
<table>
    <tr class="required">
        <th>{label partner /}</th>
        <td>{input partner}</td>
    </tr>

    <tr class="required">
        <th>{label product /}</th>
        <td>{input product}</td>
    </tr>
    <tr>

        <th>{label parameters /}</th>
        <td>
        {snippet}
            {input parameters}
        {/snippet}
        </td>

    </tr>
    <tr>
        <th>&nbsp;</th>
        <td>{input submit}</td>
    </tr>
</table>
{/form}

<script>
$("#frmconnection-product").live("change", function(e) {
        $.get(basePath+"?do=change&product_id="+$("#frmconnection-product").val());
        e.preventDefault();
    });
</script>

Dakujem za akukolvek pomoc.

Vdaka,

Miso