nur-sery/nur_src/v/plugins/autosubmitOnEventPlugin.php

39 lines
882 B
PHP
Raw Normal View History

2024-06-21 12:54:40 +04:00
<?php
namespace nur\v\plugins;
use nur\v\BasePlugin;
use nur\v\js;
/**
* Class autosubmitSelectPlugin: soumet le formulaire sur l'événement change
*/
2024-08-20 23:07:07 +04:00
class autosubmitOnEventPlugin extends BasePlugin {
2024-06-21 12:54:40 +04:00
const HAVE_JQUERY = true;
2024-08-20 23:07:07 +04:00
function __construct(string $selector, string $event="change", bool $cond=true) {
2024-06-21 12:54:40 +04:00
$this->selector = $selector;
2024-08-20 23:07:07 +04:00
$this->event = $event;
2024-06-21 12:54:40 +04:00
$this->cond = $cond;
}
/**
* @var string sélecteur pour les composants concernés.
*/
private $selector;
2024-08-20 23:07:07 +04:00
/** @var string événement sur lequel déclencher la soumission du formulaire */
private $event;
2024-06-21 12:54:40 +04:00
/** @var bool ce plugin est-il activé? */
private $cond;
function printJquery(): void {
if (!$this->cond) return;
?>
2024-08-20 23:07:07 +04:00
$(<?=js::qv($this->selector)?>).on(<?=js::qv($this->event)?>, function() {
2024-06-21 12:54:40 +04:00
$(this).closest("form").submit();
return false;
});
<?php
}
}