Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Merge pull request #1069 from aaronschmitz/form_order
Browse files Browse the repository at this point in the history
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 19469d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libraries/joomla/form/form.php
Expand Up @@ -711,11 +711,14 @@ public function load($data, $replace = true, $xpath = false)
if ($current = $this->findField((string) $field['name'], implode('.', $groups))) 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) if ($replace)
{ {
$dom = dom_import_simplexml($current); $olddom = dom_import_simplexml($current);
$dom->parentNode->removeChild($dom); $loadeddom = dom_import_simplexml($field);
$addeddom = $olddom->ownerDocument->importNode($loadeddom);
$olddom->parentNode->replaceChild($addeddom, $olddom);
$loadeddom->parentNode->removeChild($loadeddom);
} }
else else
{ {
Expand Down
13 changes: 13 additions & 0 deletions tests/suites/unit/joomla/form/JFormTest.php
Expand Up @@ -1301,6 +1301,19 @@ public function testLoad()
$this->equalTo(1), $this->equalTo(1),
'Line:'.__LINE__.' The show_title in the params group has been replaced by show_abstract.' '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.'
);
}
} }


/** /**
Expand Down

0 comments on commit 19469d4

Please sign in to comment.