dependent select, snippety a Bs3FormRenderer
- pp
- Člen | 50
Ahoj,
prosim o radu. Chci mit formular „addNode“ obsahujici vetsi pocet vstupu a
krome jinyho taky vyber adresniho mista pomoci dependent selectu (mesto, ulice,
cp).
Pokud chci dynamicky nacitat obsah pro adresu, mel bych to asi resit pres
snippety.
A pokud to udelam tak jak uvedeno nize, tak prijdu o elegantni vykresleni
pomoci Bs3FormRenderer() a musim to delat rucne – jak se tohle resi ?
PRESENTER
protected function createComponentAddNodeForm() {
$form = new UI\Form;
$form->addText('sn', 'SN:');
... dalsi input polozky
$form->addSelect('first', 'Obec', $this->serviceManager->getList())->setPrompt('Vyber obec');
$form->addSelect('second', 'Ulice:')->setPrompt('Nejdříve vyberte obec');
$form->addSelect('third', 'Cislo:')->setPrompt('Nejdříve vyberte ulici');
$form->addSubmit('send', 'OK');
$form->onSuccess[] = function(UI\Form $form) {
$values = $form->getHttpData();
unset($values['send']);
$this->nodeManager->addNode($values);
$this->redirect('action', [ $values ]);
};
$form->setRenderer(new \App\Forms\Bs3FormRenderer());
return $form;
}
LATTE
{snippetArea wrapper}
{form addNodeForm class => 'form-horizontal'}
...
{label first /} {input first class => 'form-control text'}
{snippet secondSnippet}
{label second /} {input second class => 'form-control text'}
{snippet thirdSnippet}
{label third /} {input third class => 'form-control text'}
{/snippet}
{/snippet}
...
{input send class => 'btn btn-primary button'}
{/form}
{/snippetArea}
- pp
- Člen | 50
tak nevim, jestli jsem to blbe popsal … zkusim to jeste jednou
Pokud v presenteru vytvorim createComponentAddNodeForm() a navazu na nej Bs3FormRenderer() a v LATTE pouziju makro {control addNodeForm} tak se mi pekne vsechno obali do <divu> s tridama podle definice v rendereru a vykresli jako BS3.
Protoze ale potrebuju uvnitr dependentselectbox a mam to reseny pres snippety
tak to asi musim kreslit rucne.
Jde mi o to jestli musim v tomhle pripade vsechny labely a inputy obalovat
rucne, nebo jesli se tomu formu nejak da vnutit ten wrapper
z Bs3FormRendereru ?
{snippetArea wrapper}
{form addNodeForm class => 'form-horizontal'}
<div class="form-group">
<div class="col-sm-3 control-label">
{label hw_id /}
</div>
<div class='col-sm-6'>
{input hw_id class => 'form-control form-control-lg text'}
</div>
</div>
<div class="form-group">
<div class="col-sm-3 control-label">
{label sn /}
</div>
<div class='col-sm-6'>
{input sn class => 'form-control form-control-lg text'}
</div>
</div>
{snippet secondSnippet}
...
{/snippet}
...
{/snipperArea}
- pp
- Člen | 50
diky za postrceni ale porad mi to nefunguje spravne.
Pro rucne renderovany form jsem zrusil $form->setRenderer(new \Nextras\Forms\Rendering\Bs3FormRenderer());
Zavedl jsem si:
extensions:
nextras.form: Nextras\Forms\Bridges\NetteDI\FormsExtension
OK, k labelu a inputu se prida trida „control-label“ a „form-control“ ale neodpovida to tomu co je vyrenderovano pres Bs3FormRenderer()
<div class="form-group">
<div class="col-sm-3 control-label"><label>AAA:</label></div>
<div class="col-sm-9"><input type="text" name="BBB" class="form-control text" id="XXX"></div>
</div>
Nevim jestli to tak ma byt, kazdopadne jsem si zkusil upravit makra
BS3InputMacros.
Obalim si label a input ale nevim jak tam jeste pridat pres oba prvky ten
<div class=„form-group“>
Pomerne v tom plavu tak bych poprosil jestli mi nekdo muze nazorne ukazat jak
na dotahnout?
public static function label(Html $label, BaseControl $control, $isPart)
{
if ($label->getName() === 'label' && !$isPart) {
$div = Html::el('div')->class('col-sm-3 control-label');
$div->addHtml($label);
$label = $div;
}
return $label;
}
public static function input(Html $input, BaseControl $control, $isPart)
{
$name = $input->getName();
if ($name === 'select' || $name === 'textarea' || ($name === 'input' && !in_array($input->type, ['radio', 'checkbox', 'file', 'hidden', 'range', 'image', 'submit', 'reset']))) {
$div = Html::el('div')->class('col-sm-9');
$input->addClass('form-control text');
$div->addHtml($input);
$input = $div;
} elseif ($name === 'input' && ($input->type === 'submit' || $input->type === 'reset')) {
$input->setName('button');
$input->addHtml($input->value);
$input->addClass('btn');
}
return $input;
}