Formular – snippety, refresh
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- steelbull
- Člen | 241
Ajaxovo odoslem formular, ktorym pridam do selectboxu novu hodnotu, ale:
- Neviem, ako mam refreshnut ten selectbox
- Neviem, ako mam vypisat flashmessage
/**
* LrForm create
*
* @return type
*/
public function createComponentLrform() {
$form = (new LrFormFactory($this, 'LrFormSuccess', $this->context, $this->translator))->create();
return $form;
}"
public function LrFormDefaults($id) {
// Try load data from the model
$model = new Model\LabRequestsModel($this->context);
try {
$data = $model->getLabRequest($id);
if (!isset($data->id)) {
throw new \PDOException($this->translator->translate('flash.record_cant_load'), 404);
}
} catch (\PDOException $e) {
$this->flashMessage($e->getMessage(), 'danger');
$this->redirect('Lr:default');
}
$this['lrform']->setDefaults($data);
}
/**
* LrForm Success
*
* @param Form $form
*/
public function lrFormSuccess(Form $form) {
$model = new Model\LabRequestsModel($this->context);
try {
$model->saveLabRequest($form->getValues());
$this->flashMessage($this->translator->translate('flash.record_was_saved'), 'success');
$this->redirect('Lr:default');
} catch (\PDOException $e) {
$this->flashMessage($this->translator->translate('flash.error_while_saving_record'), 'success');
$this->redirect('Lr:default');
}
//$this->invalidateControl('lrform');
$this->redrawControl();
}
Editoval steelbull (6. 11. 2014 11:11)
- steelbull
- Člen | 241
…a javascript ktory pouzivam vyzera takto:
…a chcem dosiahnut, aby po stlaceni tlacidla, ktore nie je sucastou formu som ho ajaxovo odoslal.
dakujem.
$(document).ready(function () {
$('form.ajax').submit(
function (event) {
event.preventDefault();
var $this = $(this);
$.ajax({
type: 'POST',
url: $this.attr('action'),
data: $this.serialize(),
success: function (data) {
$('.error-wrapper').html(data);
}
});
}
);
$('button.form-submit').each(function () {
$(this).click(function () {
var target = $(this).attr('form-target');
document.getElementById(target).submit();
});
});
});