This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #1069 from aaronschmitz/form_order

Fix JForm::load() not replacing form field in same location (Issue #129)
  • Loading branch information...
chdemko committed Apr 13, 2012
2 parents aaf8ddf + 4fba270 commit 19469d40549c28aa4212fe33b6dd1672e15b9eba
Showing with 19 additions and 3 deletions.
  1. +6 −3 libraries/joomla/form/form.php
  2. +13 −0 tests/suites/unit/joomla/form/JFormTest.php
@@ -711,11 +711,14 @@ public function load($data, $replace = true, $xpath = false)
if ($current = $this->findField((string) $field['name'], implode('.', $groups)))
{
- // If set to replace found fields remove it from the current definition.
+ // If set to replace found fields, replace the data and remove the field so we don't add it twice.
if ($replace)
{
- $dom = dom_import_simplexml($current);
- $dom->parentNode->removeChild($dom);
+ $olddom = dom_import_simplexml($current);
+ $loadeddom = dom_import_simplexml($field);
+ $addeddom = $olddom->ownerDocument->importNode($loadeddom);
+ $olddom->parentNode->replaceChild($addeddom, $olddom);
+ $loadeddom->parentNode->removeChild($loadeddom);
}
else
{
@@ -1301,6 +1301,19 @@ public function testLoad()
$this->equalTo(1),
'Line:'.__LINE__.' The show_title in the params group has been replaced by show_abstract.'
);
+
+ $originalform = new JFormInspector('form1');
+ $originalform->load(JFormDataHelper::$loadDocument);
+ $originalset = $originalform->getXML()->xpath('/form/fields/field');
+ $set = $form->getXML()->xpath('/form/fields/field');
+ for ($i = 0; $i < count($originalset); $i++)
+ {
+ $this->assertThat(
+ (string) ($originalset[$i]->attributes()->name) == (string) ($set[$i]->attributes()->name),
+ $this->isTrue(),
+ 'Line:'.__LINE__.' Replace should leave fields in the original order.'
+ );
+ }
}
/**

0 comments on commit 19469d4

Please sign in to comment.