Jump to content

Dodatkowy typ pola w HelperForm


gielet

Recommended Posts

Siemanko,

Chciałbym, aby układ strony kontrolera był w 3 kolumnach - tj. aby w jednej linii wyświetlały mi się 3 formularze po 4/12 kolumny każdy.

Znalazłem taki tutorial: Link

Do pliku modules/module-name/controllers/admin/AdminPseEgoController.php dodałem taki kod:

public function initContent()
	{
		parent::initContent();
		
		$this->context->smarty->assign(
			array(
				'1form' => $this->display1Form(),
				'2form' => $this->display2Form(),
				'3form' => $this->display3Form(),
			)
		);
		$content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'module-name/views/templates/admin/ego/ego.tpl');
		$this->context->smarty->assign(array(
             'content' => $this->content . $content,
        ));
	}

Ok, w pliku modules/module-name/views/templates/admin/ego/ego.tpl dodałem wiersz i 3 kolumny w których wyświetlam formularze w sposób {1form} / {2form} / {3form}.

Super, wygląda tak jak chciałem - nie wiem tylko, czy robię to poprawnie :|

Teraz druga sprawa - potrzebuję dodać nowe pola do HelperForm.

Wyczytałem na jakimś forum żeby dodać swój plik w takiej lokalizacji:

module-name/views/templates/admin/_configure/helpers/form/form.tpl

i w tym pliku dałem taki kod:

{extends file="helpers/form/form.tpl"}
{block name="field"}
    {if $input.type == 'rangeslider'}
        <div class="col-lg-9">
            <div id="slider-range"></div>
            <p>
                <label for="amount">Price range:</label>
                <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
            </p>
        </div>
        <script type="text/javascript">
        {literal}
            $( function() {
                $( "#slider-range" ).slider({
                     range: true,
                     min: {/literal}{$input.min|intval}{literal},
                     max: {/literal}{$input.max|intval}{literal},
                     step: {/literal}{$input.step|intval}{literal},
                     slide: function( event, ui ) {
                         $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
                     }
                });
                $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
                    " - $" + $( "#slider-range" ).slider( "values", 1 ) );
            });
        {/literal}
        </script>
    {else}
        {$smarty.block.parent}
    {/if}
{/block}

ok - w konfiguracji moduły pole działa.

Ale ja chcę to pole mieć dostępne w kontrolerze - wyczytałem, że zamiast do tej lokalizacji:

module-name/views/templates/admin/_configure/helpers/form/form.tpl

muszę dać plik form.tpl do

module-name/views/templates/admin/controllername/helpers/form/form.tpl

w moim przypadku kontroler ma nazwę AdminPseEgoController.php, więc moja lokalizacja dla tego pliku powinna być taka:

module-name/views/templates/admin/pse_ego/helpers/form/form.tpl

Ale niestety to nie działa - czy ktoś może mi pomóc, bo krew mnie zalewa :(

Link to comment
Share on other sites

  • 4 months later...

Chyba nie jest zalecane zaczynanie zmiennych od liczby.

Jeżeli chodzi o typ formularza to jest też na to inny sposób. Nie ma tego w dokumentacji, ale jak zajrzysz w \admin\themes\default\template\helpers\form\form.tpl to tam widać, że jest dostępne pole formularz typu html i w ten sposób, możesz wstawić w zasadzie dowolny kod.


 

								{elseif $input.type == 'html'}
									{if isset($input.html_content)}
										{$input.html_content}
									{else}
										{$input.name}
									{/if}
								{/if}



Coś takiego robisz w kontrolerze:

 

            $this->fields_form['input'] = array_merge(
                array(
                    array(
                        'type' => 'html',
                        'label' => $this->l('Jakiś html'),
                        'html_content' => $string_z_kodem_html,
                    )
                ),
                $this->fields_form['input']
            );

 

Edited by marcin_jaworski (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...