Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.1.0

Bug #19063 error in JS _clearErrors()
Submitted: 2011-11-21 17:02 UTC
From: loki Assigned: avb
Status: Closed Package: HTML_QuickForm2 (version 0.6.1)
PHP Version: irrelevant OS: irrelevant
Roadmaps: (Not assigned)    

 [2011-11-21 17:02 UTC] loki (Alexander Levin)
Description: ------------ function _clearErrors(element) { var spans = element.getElementsByTagName('span'); for (var i = 0, span; span = spans[i]; i++) { if (qf.classes.has(span, 'error')) { span.parentNode.removeChild(span); } } }; function has followed errors: 1. after remove "span" from "spans", "spans" becomes one element less. So indexes sifts. Iterator "i" still rise and some spans are skips. 2. function does not remove the "error" class of the parent element. It's problem for chained rules.


 [2011-11-21 19:02 UTC] loki (Alexander Levin)
-Operating System: +Operating System: irrelevant -PHP Version: 5.2.9 +PHP Version: irrelevant
 [2011-11-22 16:42 UTC] loki (Alexander Levin)
possible solution: function _clearErrors(element) { var spans = element.getElementsByTagName('span'); for (var i = 0, span; span = spans[i]; i++) { if (qf.classes.has(span, 'error')) { qf.classes.remove(span.parentNode, ['error', 'valid']); span.parentNode.removeChild(span); i--; } } };
 [2011-11-22 22:45 UTC] avb (Alexey Borzov)
-Status: Open +Status: Analyzed
1. Confirmed, getElementsByTagName() returns NodeList and that indeed reflects changes in the DOM tree: 2. Can you please provide a test script where this matters? AFAIR, _clearErrors() is run immediately before validation and "error" / "valid" classes are set / reset there.
 [2012-02-20 13:24 UTC] avb (Alexey Borzov)
Here is a complete test case: ========== require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; $form = new HTML_QuickForm2('bug19063'); $first = $form->addText('first')->setLabel('First:'); $second = $form->addText('second')->setLabel('Second:'); // Third element is mostly needed to prevent form submit $third = $form->addText('third')->setLabel('Third:'); $form->addSubmit('send', array('value' => 'Test a bug!')); $first->addRule( 'nonempty', 'First should be not empty', null, HTML_QuickForm2_Rule::CLIENT_SERVER )->or_($second->createRule( 'nonempty', 'or second should be not empty' )); $third->addRule( 'nonempty', 'Third should be not empty', null, HTML_QuickForm2_Rule::CLIENT_SERVER ); $renderer = HTML_QuickForm2_Renderer::factory('default'); $form->render($renderer); // Output javascript libraries, needed for client-side validation echo $renderer->getJavascriptBuilder()->getLibraries(true, true); echo $renderer; ========== How to reproduce: 1) Click submit without filling any fields --- 3 errors, then 2) Input something into "First", click submit --- error on "Second" does not disappear, then 3) Click submit once again --- error on "Second" disappears, but 'error' class is kept.
 [2012-02-22 15:02 UTC] avb (Alexey Borzov)
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: avb
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.