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.

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

Mea culpa,

I had to add the name of the group:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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