Skip to content

Instantly share code, notes, and snippets.

@HitnyCZ
Created March 2, 2021 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HitnyCZ/3c83620305f484f3942a101cbb832eb5 to your computer and use it in GitHub Desktop.
Save HitnyCZ/3c83620305f484f3942a101cbb832eb5 to your computer and use it in GitHub Desktop.
Naja event success
{form ajaxForm, class => "ajax"}
{input name}
{input send}
{/form}
<?php
declare(strict_types = 1);
namespace App\Controls;
use Nette\Application\UI\Control;
class AjaxControl extends Control
{
public function render()
{
$this->template->setFile(__DIR__ . '/template/ajax.latte');
$this->template->render();
}
/**
* @return Form
*/
protected function createComponentAddCart(): Form
{
$form = new Form();
$form->addText('name', 'Jméno');
$form->addSubmit('send', 'Odeslat');
$form->onSuccess[] = function (Form $form, ArrayHash $values) {
$this->presenter->payload->name = $values->name;
$this->redrawControl();
};
return $form;
}
}
import naja from "naja";
naja.addEventListener('success', (event) => {
console.log(event.detail.payload);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment