J4 Modal Form Field

133 views
Skip to first unread message

Alex Chartier

unread,
Jul 13, 2022, 3:36:37 PM7/13/22
to Joomla! General Development
Under J3 in my form xml I am able to create modal fields. When J4 parses these it fails miserably. Has anyone gotten this to work on J4?

Here is the xml I am using:

 <fieldset name="basic" label="MY_LABEL" addfieldpath="/administrator/components/mycomponent/models/fields">
            <field name="list_elements"
                   type="mymodalrepeat"
                   label="MY_LABEL"
                   description="MY_DESC"
            >
                <fields name="params">
                    <fieldset modal="true" name="list_elements_modal" repeat="true" addfieldpath="/administrator/components/mycomponent/models/fields">
                        <field name="show_in_list"
                               type="listfields"
                               size="30"
                               multiple="true"
                               label="MY_HEADING"
                        />
                    </fieldset>
                </fields>
            </field>
</fieldset>

The above is a snippet from the full file. When I comment it out the form renders fine. The files mymodalrepeat.php and listfields.php are not being called, I checked this with phpstorm.

I am at a loss, anyone have any ideas? Thanks in advance.

Peter @ GMail

unread,
Jul 13, 2022, 3:51:55 PM7/13/22
to joomla-de...@googlegroups.com
Alex,

Try replacing addfieldpath with addfieldprefix="Field Namespace".

Where Field Namespace is defined within the field.

e.g.

namespace Eluceo\Plugin\User\EluceoProfile\Field;

I hope that helps.

Peter.
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to joomla-dev-gene...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/joomla-dev-general/c9519ed6-9a8f-419d-94d0-ff3d2960162an%40googlegroups.com
> .

--
Dr. Peter Tuson BSc Hons, PhD, CEng MIET
email; pe...@tuson.org.uk

Sent from my Linux laptop.

Alex Chartier

unread,
Jul 13, 2022, 4:01:32 PM7/13/22
to Joomla! General Development
I don't think that is the problem as I am still using the addfieldpath in other forms and J! is finding the fields just fine. It is something about this modal markup J! doesn't seem to like.

Peter @ GMail

unread,
Jul 13, 2022, 4:19:23 PM7/13/22
to joomla-de...@googlegroups.com
Alex,

Sometime I had to add equivalent to the following in my module.php
file.

if
(!class_exists('\\Eluceo\Module\\WhatCareer\\Site\\Field\\NotificationF
ield')) {
require_once __DIR__ . '/src/Field/NotificationField.php';
}

This is for a module used as a modal.

Regards,

Peter.

MarkRS

unread,
Jul 13, 2022, 4:19:32 PM7/13/22
to Joomla! General Development
addfieldprefix is the J4 way of doing this, it references namespaces.

What other fields are being found, and have you tried Peter's suggestion and what happened?

Alex Chartier

unread,
Jul 13, 2022, 4:28:21 PM7/13/22
to Joomla! General Development
Perhaps I left some information out. This form is part of a menu item. When the menu type is chosen then this form default.xml file is loaded by com_menu. The form loads fine with many other fields which are found in my addfieldpath if I simply comment out the modal fields so the form loader is finding the custom fields OK for those other fields. Just the modal ones are giving me the problem. Also, interestingly, with this modal field in the form xml all other fields refuse to display, only the single field which looks like a textbox with the MY_LABEL presented un translated.

MarkRS

unread,
Jul 14, 2022, 7:33:47 AM7/14/22
to Joomla! General Development
Since you're using a good ide, have you tried stepping through the code that creates the form to see where the problem is?

Hannes Papenberg

unread,
Jul 14, 2022, 7:42:32 AM7/14/22
to Joomla! General Development
It could be, that the xpath used to parse the form has been changed, resulting in the xpath only matching your subform. You might want to look at that.

MarkRS

unread,
Jul 14, 2022, 7:56:24 AM7/14/22
to Joomla! General Development
Looks to me like modal is no longer defined in the xml but is a class definition (or specified in a link, but that's not your case perhaps).
Have a look through /libraries/src/Form for instances of "modal" and you'll see how it's used now.

Alex Chartier

unread,
Jul 14, 2022, 8:25:16 AM7/14/22
to Joomla! General Development
OK, further testing. The default.xml file that described the form fields for the menu item has 2 sets of fields. The first is the request fields which define the extra fields that will display on the details tab, the second defines a component specific tab with component specific configuration fields. There can actually be multiple extra component tabs but for now I am just using the one.

The interesting thing is that if I move the modal field and subform to the requests fields area it renders correctly. There is still something wrong when it renders the second tab though, the modal field is also showing up at the top of the tab as a text box (which I understand to mean it cannot find the field type so defaults to text) and the other fields for this tab are rendered underneath correctly. If I eliminate the second tab altogether the menu form renders correctly with my modal field and the modal popup works. All very strange behavior.

I will try and step through and see if I can figure out what is going wrong. I did not find anything useful in the libraries/src/Form files.

Alex Chartier

unread,
Jul 18, 2022, 4:08:24 PM7/18/22
to Joomla! General Development
OK. I have finally found the problem. It has nothing to do with which tab the modal field is on, it is just more obvious when it is on a secondary tab. The problem was introduced into J4 in a commit to layouts/joomla/edit/params.php which tested to see if a field had children. Part of this logic included child fieldsets. Anyway I made a change to the search logic and the problem has gone away.

I have opened a ticket on the joomla issue tracker. My way of solving the problem may not be the final solution, but at least I have something that is working.

Thanks to all for your suggestions and support.

Alex Chartier

unread,
Jul 25, 2022, 5:52:07 PM7/25/22
to Joomla! General Development
Failing help from our friends at J!, I can solve this with a layout override. This would require my component to insert a layout override into the site admin template. Does this seem a reasonable option for a component to do? It would have to be into the template layouts override folder
Reply all
Reply to author
Forward
0 new messages