mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 22:04:25 +02:00
Make autosubmit work in non-JS enviroments
We require forms to set autosubmit=true on elements which are supposed to be submitted automatically now. The base form then ensures that this works in JS environments and non-JS environments as well by applying the right changes to the HTML. refs #5525
This commit is contained in:
parent
486104d59e
commit
bf23688e73
@ -8,6 +8,7 @@ use Zend_Form;
|
|||||||
use Zend_View_Interface;
|
use Zend_View_Interface;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Web\Form\Decorator\HelpText;
|
use Icinga\Web\Form\Decorator\HelpText;
|
||||||
|
use Icinga\Web\Form\Decorator\NoScriptApply;
|
||||||
use Icinga\Web\Form\Decorator\ElementWrapper;
|
use Icinga\Web\Form\Decorator\ElementWrapper;
|
||||||
use Icinga\Web\Form\Element\CsrfCounterMeasure;
|
use Icinga\Web\Form\Element\CsrfCounterMeasure;
|
||||||
|
|
||||||
@ -330,6 +331,14 @@ class Form extends Zend_Form
|
|||||||
$el->removeDecorator('HtmlTag');
|
$el->removeDecorator('HtmlTag');
|
||||||
$el->removeDecorator('Label');
|
$el->removeDecorator('Label');
|
||||||
$el->removeDecorator('DtDdWrapper');
|
$el->removeDecorator('DtDdWrapper');
|
||||||
|
|
||||||
|
if ($el->getAttrib('autosubmit')) {
|
||||||
|
// Need to add this decorator first or it interferes with the other's two HTML otherwise
|
||||||
|
$el->addDecorator(new NoScriptApply()); // Non-JS environments
|
||||||
|
$el->setAttrib('class', 'autosubmit'); // JS environments
|
||||||
|
unset($el->autosubmit);
|
||||||
|
}
|
||||||
|
|
||||||
$el->addDecorator(new ElementWrapper());
|
$el->addDecorator(new ElementWrapper());
|
||||||
$el->addDecorator(new HelpText());
|
$el->addDecorator(new HelpText());
|
||||||
}
|
}
|
||||||
|
35
library/Icinga/Web/Form/Decorator/NoScriptApply.php
Normal file
35
library/Icinga/Web/Form/Decorator/NoScriptApply.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Web\Form\Decorator;
|
||||||
|
|
||||||
|
use Zend_Form_Decorator_Abstract;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decorator to add a submit button encapsulated in noscript-tags
|
||||||
|
*
|
||||||
|
* This enables users in non-JS environments to update the contents
|
||||||
|
* of a form without the use of the main submit button.
|
||||||
|
*/
|
||||||
|
class NoScriptApply extends Zend_Form_Decorator_Abstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Add a submit button encapsulated in noscript-tags to the element
|
||||||
|
*
|
||||||
|
* @param string $content The html rendered so far
|
||||||
|
*
|
||||||
|
* @return string The updated html
|
||||||
|
*/
|
||||||
|
public function render($content = '')
|
||||||
|
{
|
||||||
|
if ($content) {
|
||||||
|
$content .= '<noscript><button name="noscript_apply" style="margin-left: 0.5em;" type="submit" value="1">'
|
||||||
|
. Icinga::app()->getViewRenderer()->view->icon('refresh.png') . ' ' . t('Apply')
|
||||||
|
. '</button></noscript>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user