?
avatar dr138
dr138
15 Mar 2016

Steps to reproduce the issue

The

foreach ($elements as $element)
{
...
}

loop within findField should have the loop variable renamed to (eg) $el, otherwise it can end up being returned as the function return value.

Eg for

$jform = new JForm('testform');
$jform->load(<<<'XML'
<form>
  <fields name="A">
    <field name="fielda"/>
    <fields name="B">
      <field name="fieldab"/>
    </fields>
  </fields>
</form>
XML
);
$field = $jform->findField('fieldab','A'); // should return false, but returns whole <fields name="A"> element.
print ($field? $field->asXML()."\n": "false")."\n";

And then for

$jform->load(<<<'XML'
<form>
<fields name="A">
  <field name="fieldab"/>
</fields>
</form>
XML
,true); // should add a new <field name="fieldab"/> element to the <fields name="A"> element, instead deletes the whole original <fields name="A"> element and adds the <field> at the "top" level.
print $jform->getxml()->asXML();

David

Expected result

See commented code above

Actual result

See commented code above

System information (as much as possible)

Additional comments

avatar dr138 dr138 - open - 15 Mar 2016
avatar izharaazmi
izharaazmi - comment - 14 May 2016

I confirm this issue exists.

But...., the given code won't execute from outside JForm as findField is a protected method. Using getField will still return false because field setup fails at libraries/joomla/form/form.php:1823 as libraries/joomla/form/field.php:557 returns false.

@dr138 Please send a PR.

avatar brianteeman brianteeman - change - 3 Aug 2016
Status New Confirmed
avatar brianteeman
brianteeman - comment - 22 Aug 2016

Closed as we have a PR #11732

avatar brianteeman brianteeman - change - 22 Aug 2016
Status Confirmed Closed
Closed_Date 0000-00-00 00:00:00 2016-08-22 17:39:44
Closed_By brianteeman
avatar brianteeman brianteeman - close - 22 Aug 2016

Add a Comment

Login with GitHub to post a comment