0

I would like to add some data to a form field I declared in my forms.xml. This form field is a custom form field which is declared like this:

<fields name = "userdata">
    <fieldset name = "personal-data">
        <field name = "test" 
           type = "myfield" 
           size = "40" 
           country = "DE"
           label = "COM_BESTIA_FIELDS_TEST_LABEL"
           description = "COM_BESTIA_FIELDS_TEST_DESC" 
           required = "true" 
           filter = "safehtml" />
    </fieldset>
</fields>

Now I would like to use

$form = $this->loadForm('com_bestia.item', 'item', array('control' => 'jform', 'load_data' => $loadData));
$form->setFieldAttribute('test', 'country', 'US');

to add a specific value to the country attribute.

If I do that this way, there are no changes - it still shows DE.

3
  • Have you tried $form->setValue() instead Apr 25, 2016 at 14:17
  • Hm, still no success :-( No error-message or something like that.
    – MyFault
    Apr 25, 2016 at 17:05
  • I tried to do it with $form->setValue('test', 'country', 'US');
    – MyFault
    Apr 25, 2016 at 17:12

1 Answer 1

3

Mea culpa,

I had to add the name of the group:

$form->setFieldAttribute('test', 'country', 'US', 'personal');
1
  • If this solved your issue, please award the green tick to your answer so that this page is deemed to be resolved. Jun 10, 2018 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.