Merge pull request #4655 from Icinga/fix/duplicate-ids-in-html-3762

Fix duplicate ids in html
This commit is contained in:
Johannes Meyer 2022-02-04 17:26:48 +01:00 committed by GitHub
commit 49ced694e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 4 deletions

View File

@ -1085,7 +1085,7 @@ class Form extends Zend_Form
return $this;
}
if ($this->getElement($this->tokenElementName) === null) {
$this->addElement(new CsrfCounterMeasure($this->tokenElementName));
$this->addElement('CsrfCounterMeasure', $this->tokenElementName);
}
}
return $this;

View File

@ -40,7 +40,7 @@ class CsrfCounterMeasure extends FormElement
*/
public function init()
{
$this->addDecorator('ViewHelper');
$this->setDecorators(['ViewHelper']);
$this->setValue($this->generateCsrfToken());
}

View File

@ -4,6 +4,7 @@
<li>
<?php
$removeAckForm = clone $removeAckForm;
$removeAckForm->setName('quickAction_' . $removeAckForm->getName()); // Avoids id duplication
$removeAckForm->setLabelEnabled(true);
echo $removeAckForm;
?>
@ -42,6 +43,7 @@
</li>
<?php endif ?>
<?php if (isset($checkNowForm)): // Form is unset if the current user lacks the respective permission ?>
<?php ($checkNowForm = clone $checkNowForm)->setName('quickAction_' . $checkNowForm->getName()); // Avoids id duplication ?>
<li><?= $checkNowForm ?></li>
<?php endif ?>
<?php if ($this->hasPermission('monitoring/command/comment/add')): ?>

View File

@ -373,8 +373,8 @@
while (true) {
var id = element.id;
// Ignore forms and form controls because id generation is unreliable :(
if (id && ! element.form && ! (element instanceof HTMLFormElement)) {
// Only use ids if they're truly unique
if (!! id && document.querySelectorAll('* #' + id).length === 1) {
path.push('#' + id);
break;
}