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

Bug #20295 Repeat: if defaults contain null values, previous values are reused
Submitted: 2014-06-12 23:00 UTC
From: avb Assigned: avb
Status: Closed Package: HTML_QuickForm2 (version 2.0.0)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: 2.0.1    
Subscription  


 [2014-06-12 23:00 UTC] avb (Alexey Borzov)
Description: ------------ If default value for an element within repeated item is a null (which may easilly come from a database), instead of setting an empty value for it the value from a previous repeated item is kept. Possible fix: when iterating over items' indexes, should probably reset elements' values on each iteration instead of once in restoreChildAttributes() Test script: --------------- $form = new HTML_QuickForm2('repeat-bug'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array( 'buggy' => array( 'name' => array( 1 => 'First', 2 => 'Second' ), 'extra' => array( 1 => 'Has extra', 2 => null ) ) ))); $group = new HTML_QuickForm2_Container_Group('buggy'); $group->addText('name'); $group->addText('extra'); $repeat = $form->addRepeat(null, array('id' => 'buggy-repeat'), array('prototype' => $group)); $value = $repeat->getValue(); var_dump($value['buggy']['extra'][2]); Expected result: ---------------- NULL or maybe string(0) "" Actual result: -------------- string(9) "Has extra"

Comments

 [2014-06-19 22:52 UTC] avb (Alexey Borzov)
-Status: Open +Status: Closed -Assigned To: +Assigned To: avb
Fixed in Git. https://github.com/pear/HTML_QuickForm2/commit/e58cb3af31af0f00875bc8a6c919a1fd166c201a
 [2014-06-26 18:58 UTC] avb (Alexey Borzov)
Implemented a proper fix: elements now can check whether a DataSource contains a value for an element even if the value is null and use that value. https://github.com/pear/HTML_QuickForm2/commit/c07dd7ffa3d0468cd4f7df8be5ed62e9ae49e1fe