35 lines
706 B
PHP
35 lines
706 B
PHP
<?php
|
|
namespace nur\v\plugins;
|
|
|
|
use nur\v\BasePlugin;
|
|
use nur\v\js;
|
|
|
|
/**
|
|
* Class autosubmitSelectPlugin: soumet le formulaire sur l'événement change
|
|
*/
|
|
class autosubmitOnChangePlugin extends BasePlugin {
|
|
const HAVE_JQUERY = true;
|
|
|
|
function __construct(string $selector, bool $cond=true) {
|
|
$this->selector = $selector;
|
|
$this->cond = $cond;
|
|
}
|
|
|
|
/**
|
|
* @var string sélecteur pour les composants concernés.
|
|
*/
|
|
private $selector;
|
|
|
|
/** @var bool ce plugin est-il activé? */
|
|
private $cond;
|
|
|
|
function printJquery(): void {
|
|
if (!$this->cond) return;
|
|
?>
|
|
$(<?=js::qv($this->selector)?>).change(function() {
|
|
$(this).closest("form").submit();
|
|
return false;
|
|
});
|
|
<?php
|
|
}
|
|
}
|