35 lines
836 B
PHP
35 lines
836 B
PHP
|
<?php
|
||
|
namespace nur\v\plugins;
|
||
|
|
||
|
use nur\v\BasePlugin;
|
||
|
use nur\v\js;
|
||
|
|
||
|
class autosubmitSelectPlugin extends BasePlugin {
|
||
|
const HAVE_JQUERY = true;
|
||
|
|
||
|
function __construct(?string $selector, ?bool $cond=null) {
|
||
|
if ($selector === null) $selector = "select:not(.no-autosubmit)";
|
||
|
if ($cond === null) $cond = $selector? true: false;
|
||
|
$this->selector = $selector;
|
||
|
$this->cond = $cond;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @var string sélecteur pour les composants concernés. par défaut, prendre
|
||
|
* tous les éléments select qui n'ont pas la classe no-autosubmit
|
||
|
*/
|
||
|
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
|
||
|
}
|
||
|
}
|