Bug #19063 [Ana->Csd]: error in JS _clearErrors()

From: Date: Wed, 22 Feb 2012 10:02:55 +0000
Subject: Bug #19063 [Ana->Csd]: error in JS _clearErrors()
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-8303@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=19063&edit=1 ID: 19063 Updated by: borz_off@cs.msu.su Reported By: loki_angel at mail dot ru Summary: error in JS _clearErrors() -Status: Analyzed +Status: Closed Type: Bug Package: HTML_QuickForm2 Operating System: irrelevant Package Version: 0.6.1 PHP Version: irrelevant -Assigned To: +Assigned To: avb Roadmap Versions: New Comment: -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 pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net 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. Previous Comments: ------------------------------------------------------------------------ [2012-02-20 08:24:37] avb 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. ------------------------------------------------------------------------ [2011-11-22 17:45:34] avb -Status: Open +Status: Analyzed 1. Confirmed, getElementsByTagName() returns NodeList and that indeed reflects changes in the DOM tree: http://www.w3schools.com/dom/dom_nodelist.asp 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. ------------------------------------------------------------------------ [2011-11-22 11:42:36] loki 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-21 14:02:51] loki -Operating System: +Operating System: irrelevant -PHP Version: 5.2.9 +PHP Version: irrelevant ------------------------------------------------------------------------ [2011-11-21 12:02:37] loki 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. ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=19063&edit=1

« previous php.pear.bugs (#8303) next »