Dynamicke skyrvanie nefunguje so selectboxom
- Raiper34
- Člen | 65
Ahoj,
mam taky problem, ze dynamicke skryvanie formularov mi nefunguje na selectboxe. Mam nasledujuci kod v presentere:
public function createComponentPageForm()
{
$form = new Form();
$form->addSelect('type', $this->translator->translate('messages.Type'), array(0 => 'Article', 1 => 'Category'))
->addCondition(Form::EQUAL, 0)
->toggle('article_div', FALSE);
$form->addText('name', $this->translator->translate('messages.Name'))
->setAttribute('class', 'validate');
$form->addSelect('article_id', $this->translator->translate('messages.Article'), $this->modelArticle->getArticlesForSelect());
$form->addSubmit('submit', $this->translator->translate('messages.Create'))
->setAttribute('class', 'waves-effect waves-light btn ' . $this->colorClass);
$form->onSuccess[] = array($this, 'pageFormSuccess');
return $form;
}
A potom rucne vykreslujem:
{form pageForm}
<div class="input-field col s12">
{input type}
{label type /}
</div>
<div class="input-field col s12">
{input name}
{label name /}
</div>
<div class="input-field col s12" id="article_div">
{input article_id}
{label article_id /}
</div>
<div class="input-field col s12 right-align">
{input submit}
</div>
<br>
{/form}
Ked dam addCondition a ten toggle na ten textbox, tak tam to funguje a vsetko pekne skryva, ale tu toho nemozem docielit, toggle nefunguje so selectboxom, alebo kde by mohla byt chyba? Diky za rady. Edit: Mozno nepresne napisane, ide o to, ze ked sa to ma rozhodovat podla selectboxu to nefunguje, ak sa to rozhoduje podla hodnoty textboxu, tak tam to funguje a ten div skryva.
Editoval Raiper34 (9. 9. 2016 11:10)
- Raiper34
- Člen | 65
<div class="input-field col s12">
<div class="select-wrapper"><span class="caret">▼</span>
<input type="text" class="select-dropdown" readonly="true" data-activates="select-options-20c063fc-c765-2b5f-55ca-073a327ab22e" value="Article">
<ul id="select-options-20c063fc-c765-2b5f-55ca-073a327ab22e" class="dropdown-content select-dropdown" style="width: 974px; position: absolute; top: 0px; left: 0px; opacity: 1; display: none;">
<li class=""><span>Article</span></li>
<li class=""><span>Category</span></li>
</ul>
<select name="type" id="frm-pageForm-type" data-nette-rules="[{"op":":equal","rules":[],"control":"type","toggle":{"article_div":false},"arg":0}]" class="initialized">
<option value="0">Article</option>
<option value="1">Category</option>
</select>
</div>
<label for="frm-pageForm-type">messages.Type</label>
</div>
Editoval Raiper34 (9. 9. 2016 11:46)
- Jan Mikeš
- Člen | 771
Možná bude stačit, když v tom scriptu budeš ručně triggerovat event na elementu, něco jako:
<script>
$(elementSelector).trigger("change");
</script>
Protože netteForms.js mají pro selecty navěšěné toggly právě na change event: https://github.com/…etteForms.js#L605