ajax form po kliknutí na button se refreshne
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- docky
- Člen | 59
Ahoj, potýkám se už nějakou hodinku s ajax formem, při kliknutí na button submit se mi refreshne stránka, knihovnu nette.ajax mam , a $.nette.init() mám taky. muj form vypadá takhle
<div class="modal inmodal fade" id="userEdit" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" n:snippet=editForm>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"></button>
<h4 class="modal-title">Editace uživatele {$username}</h4>
</div>
<div class="modal-body">
<form class="ajax form-horizontal" n:name="editForm">
<ul class="errors" n:if="$form->hasErrors()">
<li n:foreach="$form->errors as $error">{$error}</li>
</ul>
<div class="form-group">
<label class="col-sm-2 control-label">Jméno</label>
<div class="col-sm-10">
<input class="form-control" n:name="username">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">E-mail</label>
<div class="col-sm-10">
<input class="form-control" n:name="email">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Aktivní</label>
<div class="col-sm-10">
<select class="form-control" name="active">
<option value="0">Ne</option>
<option value="1">Ano</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-primary" n:name="submit">Uložit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
protected function createComponentEditForm() {
$form = new Form;
$form->addText('username', 'jméno');
$form->addText('email', 'e-mail');
$form->addSelect('active', 'aktivní', [0 => "ne", 1 => "ano"]);
$form->addHidden('user_id');
$form->addSubmit('submit', 'uložit');
$form->onValidate[] = [$this, "validateEdit"];
$form->onSuccess[] = [$this, "processEdit"];
return $form;
}
public function validateEdit(Form $form, $values) {
$email = $this->usersFacade->findBy(["email" => $values->email]);
if ($email) {
$form['email']->addError('E-mail jíž existuje');
}
}
public function handleEdit($id) {
$user = $this->usersFacade->findOneById($id);
$this->template->username = $user->username;
$this['editForm']->setDefaults(["user_id" => $id]+$user->toArray());
$this->redrawControl('editForm');
}
?>
Nevíte někdo co s tím ? Děkuju