Replicator a závislé selecty

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

Zdravím.

Mám závislé selecty v replikátore, ktoré si pri pridaní ďalšieho replicator containera neudržia zvolenú hodnotu. Navyše, ak pridám submitu triedu ajax, ten ďalší container sa mi nevykreslí v konzole však POST vidím po každom stlačení tlačidla. Vo Firebugu v POST hodnoty inputov závislého selectu sú, v Response pre snippety už nie. Pozrel som si viacero príbuzných príspevkov, ale k riešeniu som sa nedopracoval. Ďakujem za každú radu.

Presenter


    public function handleUpdate($value, $container)
    {
        $attributes = $this->database->table('attribute_value')
            ->where('attribute', (int)$value)
            ->fetchPairs('id', 'name');

        $this['productForm']['attributes'][$container]['value']->setItems($attributes);

        if($this->isAjax()) {
            $this->redrawControl('attributesContainer');
        }
    }

    public function renderNew()
    {
        $this->template->_form = $this['productForm'];
        $this['productForm']['submit']->caption = 'Pridať';

        $this->redrawControl('attributesContainer');
    }

    protected function createComponentProductForm()
    {
        //...

        $dynamic = $form->addDynamic('attributes', function (Container $container) use ($attributes) {
            $container->addSelect('attribute', 'Atribút', $attributes)
                ->setPrompt('Vyberte atribút');
            $container->addSelect('value', 'Hodnota')
                ->setPrompt('Vyberte hodnotu');
            $container->addText('amount', 'Množstvo');

            $container->addSubmit('remove', 'Odobrať atribút')
                ->setValidationScope(FALSE)
                ->onClick[] = array($this, 'productFormRemoveElement');
        }, 1);

        $dynamic->addSubmit('add', 'Pridať ďalší atribút')
            ->setAttribute('class', 'ajax')
            ->setValidationScope(FALSE)
            ->onClick[] = array($this, 'productFormAddNewElement');

		//...

   		return $form;
    }

Latte template


...

	{snippet all}
    	{snippet attributesContainer}

			{foreach $_form['attributes']->containers as $id => $attribute}
	        	{input attributes-$id-attribute}

                {snippet attribute-$id}
	                {input attributes-$id-value}
                    {input attributes-$id-amount}
                {/snippet}

                {input attributes-$id-remove}
			{/foreach}

			{input attributes-add}

    	{/snippet}
	{/snippet}

...

   <script>
        {foreach $_form['attributes']->containers as $id => $attribute}
            {include #jsCallback, id => $id, form => 'productForm', input => $attribute['attribute']->name, link => update}
        {/foreach}
   </script>

Layout


...

    {define #jsCallback}
        $('#{$control[$form]['attributes'][$id][$input]->htmlId}').on('change', function() {
            $.nette.ajax({
            type: 'GET',
            url: '{link {$link}!}',
                data: {
                    'value': $(this).val(),
                    'container': {$id}
                }
            });
        });
    {/define}

...

Editoval jurajvt (15. 9. 2014 14:46)

johnnie
Člen | 54
+
0
-

Ahoj,

je to už rok dozadu ale riešim niečo podobné. Podarilo sa ti to vyriešiť ?

Martk
Člen | 661
+
0
-

Můžeš vyzkoušet tento doplněk Jestli ti něco nepůjde založ issue a opravím to.