0

If I have a subform with the following xml structure

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset
        name="advkontentuser"
    >
        <fieldset name="akuser" label="ADVKONTENT_USER_EDIT_FORM">
            <field
                name="akprofile"
                type="subform"
                label="AdvKontent User Profile"
                multiple="true"
                min="1"
                max="10"
                groupByFieldset="true"
                layout="joomla.form.field.subform.repeatable"
                >
                <form addfieldprefix="DeAnima\Component\AdvKontent\Administrator\Field">
                    <fieldset name="advkontent-user">
                        <fields name="details">
                            <field
                                name="userName"
                                type="text"
                                label="ADVKONTENT_NAME"
                                required="true"
                                labelclass="advkontentui-field-label"
                                maxlength="250"
                                class="advkontentui-field-value"
                            />
                            <field
                                name="gender"
                                type="radio"
                                default="n"
                                label="ADVKONTENT_GENDER"
                                labelClass="advkontentui-field-label"
                                class="advkontentui-field-value advkontentui-button-set"
                            >
                                <option value="n">ADVKONTENT_NOT_SPECIFIED</option>
                                <option value="m">ADVKONTENT_MALE</option>
                                <option value="f">ADVKONTENT_FEMALE</option>
                            </field>
                        </fields>
                    </fieldset>
                </form>
            </field>
        </fieldset>
    </fieldset>
</form>

Is it possible to add fields dynamically to the fieldset "advkontent-user" as described in the Joomla document

I've tried the following code

$form->setFields($uepSubformFields, 'akprofile', 'false', 'advkontent-user');

However it's not adding anything. Are the values for the group and fieldset correct?

1 Answer 1

0

Looking at the code in ../libraries/src/Form/Form.php the setFields() function is a wrapper function to loop through setField() starting at line #781, both of which reject any bad xml syntax. Check first that your xml you are trying to introduce is valid xml.

I would also suggest your try adding just one new sub form element using setField() rather than setFields() until you can confirm something that works.

And I would then step through each line of code in SetField() with a Debugger to identify whether your Sub form is being found or not.

Looking in Github at findFields() and related functions that setField() relies on, there doesn't appear to be much code changed since 13-14 years ago, excluding clean ups, with only one mention I could find of a change relating to sub forms so I wouldn't be surprised if adding fields to sub-forms is not yet introduced at a code level in FindFields().

This should show up in a debug when you see what is returned from findFields()

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.