From 916c9c027e78bdbfbafd4b484412c4dcd37ec068 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 20 Jun 2014 14:32:22 +0200 Subject: [PATCH] forms: fix isSubmitted Implementation made wrong assumptions. A form is submitted when the submit button has been pressed. It's value is then filled, it also is when you're just pressing "RETURN". RETURN triggers the FIRST submit button in a form. This way we are also able to find out which form button has been pressed. Current implementation is still poor, however isSubmitted works as expected right now - and so does autosubmission. fixes #5967 --- library/Icinga/Web/Form.php | 19 +++++++++++++++---- public/js/icinga/events.js | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 02c9787f4..328de50de 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -393,7 +393,13 @@ class Form extends Zend_Form foreach ($triggerElements as $elementName) { $element = $this->getElement($elementName); if ($element !== null) { - $element->setAttrib('onchange', '$(this.form).submit();'); + $class = $element->getAttrib('class'); + if ($class === null) { + $class = 'autosubmit'; + } else { + $class .= ' autosubmit'; + } + $element->setAttrib('class', $class); } else { throw new ProgrammingError( 'You need to add the element "' . $elementName . '" to' . @@ -443,13 +449,18 @@ class Form extends Zend_Form */ public function isSubmitted() { - $submitted = true; + // TODO: There are some missunderstandings and missconceptions to be + // found in this class. If populate() etc would have been used as + // designed this function would read as simple as: + // return $this->getElement('btn_submit')->isChecked(); + if ($this->submitLabel) { $checkData = $this->getRequest()->getParams(); - $submitted = isset($checkData['btn_submit']); + $label = isset($checkData['btn_submit']) ? $checkData['btn_submit'] : null; + return $label === $this->submitLabel; } - return $submitted; + return true; } /** diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 69d75ee46..18b1d4aff 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -110,6 +110,7 @@ // We support an 'autosubmit' class on dropdown form elements $(document).on('change', 'form select.autosubmit', { self: this }, this.autoSubmitForm); + $(document).on('change', 'form input.autosubmit', { self: this }, this.autoSubmitForm); $(document).on('keyup', '#menu input.search', {self: this}, this.autoSubmitSearch);