Tutorial: s AJAXem – taskList se neprekresli po zadani noveho ukolu
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- martin-army
- Člen | 6
Začínám s nette, prošel jsem si tutoriál az dokonce. Nejak nedokazu zprovoznit to, aby po vlozeni noveho ukolu se automaticky prekreslil taskList a vymazal formular.
kod, ktery tam mam:
Task/default.latte
{block content}
<h1 n:block="title">{$list->title}</h1>
{snippet form}
<fieldset>
<legend>Pridat ukol</legend>
{form taskForm class => ajax}
<div class="task-form">
{control $form errors}
{label text /} {input text size => 30, autofocus => true} {label userId /} {input userId} {input create}
</div>
{/form}
</fieldset>
{/snippet}
{control taskList}
{/block}
TaskPresenter.php (cast)
protected function createComponentTaskForm() {
$userPairs = $this->userRepository->findAll()->fetchPairs('id', 'name');
$form = new Form();
$form->addText('text', 'Úkol:', 40, 100)
->addRule(Form::FILLED, 'Je nutné zadat text úkolu.');
$form->addSelect('userId', 'Pro:', $userPairs)
->setPrompt('- Vyberte -')
->addRule(Form::FILLED, 'Je nutné vybrat, komu je úkol přiřazen.')
->setDefaultValue($this->getUser()->getId());
$form->addSubmit('create', 'Vytvořit');
$form->onSuccess[] = $this->taskFormSubmitted;
return $form;
}
public function taskFormSubmitted(Form $form) {
$this->taskRepository->createTask($this->list->id, $form->values->text, $form->values->userId);
$this->flashMessage('Ukol pridan.', 'success');
if (!$this->isAjax()) {
$this->redirect('this');
}
$form->setValues(array(), TRUE);
$this->invalidateControl('form');
$this['taskList']->invalidateControl();
}
Pokud kliknu na nazev seznamu tasku (napr Home), tak se pak prekresli a ukol
je videt.
Stejne tak nefunguje prekresleni u oznaceni „hotovo“.
Poradite, co mam spatne?
Diky.
- martin-army
- Člen | 6
mam: TaskList.latte:
{snippet}
<table class="tasks">
<thead>
<tr>
<th class="created"> </th>
<th class="list" n:if="$displayList">Seznam</th>
<th class="text">Úkol</th>
<th class="user" n:if="$displayUser">Přiřazeno</th>
<th class="action"> </th>
</tr>
</thead>
<tbody>
{foreach $tasks as $task}
<tr n:class="$iterator->isOdd() ? odd : even, $task->done ? done">
<td class="created">{$task->created|date:'j. n. Y'}</td>
<td class="list" n:if="$displayList">{$task->list->title}</td>
<td class="text">{$task->text}</td>
<td class="user" n:if="$displayUser">{$task->user->name}</td>
<td class="action"><a n:if="!$task->done" n:href="markDone! $task->id" class="icon tick ajax">hotovo</a></td>
</tr>
{/foreach}
</tbody>
</table>
{/snippet}