Created
March 2, 2021 10:32
-
-
Save HitnyCZ/3c83620305f484f3942a101cbb832eb5 to your computer and use it in GitHub Desktop.
Naja event success
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{form ajaxForm, class => "ajax"} | |
{input name} | |
{input send} | |
{/form} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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