Feature Suggestion - subform in admin list view #248
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: joomla/Component-Builder#248
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Steps to reproduce the issue
Create a Joomla Subform in JCB, then set the subform field to show on the admin list view, and filter.
This, of course, won't work since the subform is saves as a json, and the admin view has no way to know what the value is that you want populated.
Expected result
Actual result
I haven't exactly figured out the logistics yet. I've been testing with "hacking" the view and model to get it to decode the json, then output the result that I want to the view.
A thought for JCB, as subforms might start getting more and more popular, as you can save a lot of field data in a single field, is to have an option that if admin list and/or filter is selected, there is another option that show asking if this is a json. If yes, then a list shows with the fields options. IF you had, as an example, a subform with name, address, city, the list would show those options. If you selected name, then there would be a json decode for that field for the admin list, and since name was selected, name would be output to that column in the list.
This is just a thought, but I think would really expand some functionality.
System information (as much as possible)
Additional comments
Well the idea was to be able to build a modal that display the data from the json in a table layout sort of the same way as in the sub form, just without edit options. Also no sorting and filtering will be available at first, but it could be extended later... the first would just be a dynamic modal with the table layout of the data in the subform.
What do you think, will this work for a start?
Here's actually a sample of what I'm referring to.
In the sample, the column "Select a Resource/Class" and "Property Table" are custom dropdown lists in the item view, pulling the values from another view (settings and databases). In settings and databases the values are a subform. The view works good, it would just be nice to have an option to decode and display a value from the array to populate these columns. The filter dropdowns are populating correctly, just not working, which I think is because of the json not being decoded.
Give me some code examples... since it seems like we are thinking of two different concepts here.
Your idea sounds interesting as well.
But what I was thinking is instead of this code below
<td class="hidden-phone"> <?php echo $this->escape($item->resourcetypes_name); ?> </td> <td class="hidden-phone"> <?php echo $this->escape($item->proptable_name); ?> </td>
It would json_decode, then output the results. From my initial example, if resourcetypes_name had name, address, city, and I wanted the site, it could be specified.
Yes but what if there is ten rows?
If, as in the example below, each row would have the different value when it outputs the row data.
For example, at least in my example, the json is stored in a separate table, and the view has a custom field doing the lookup. If the json was:
then since it's a custom field, it is populating the value set in the custom field, in this case, recid. So, in each row for resource, there is a reference to recid: 1, 2, 3, 4, 5, etc.
A json_decode would decode that linked fields value, find recid=2, as an example, then output new york in the row, since I would have set city as the value I wanted returned.
In order for that feature to work, the subform would need to have a unique identifier.
I still do not understand.... lets start again.
Start explaining your idea from this background, so I can exactly understand how it relates to these expected realities. Meaning do we inject these rows into the exiting rows.. do we add JavaScript/Ajax that display these values based on and item selection... how do you deal with the table (subform json) in each row?
My suggestion was to in that field/subform place we add a button, which if clicked loads the table/subform values in a modal/popup basically looking exactly like the subform just without the option to edit and move the rows around.
I understand the subform format and how the JSON looks and stuff... to me the going from on field to a table is where we need to do the work, and still preserve the integrity of the Joomla core implementation.
We're definitely on different ideas here. Let's think of it this way.
Table 1 field: name, subform called details (fields recid, name, address, city)
Table 2 fields: name, custom field with city as the text and recid as the value.
The custom field in table 2 it's doing a json_decode to get the data.
In table 1 the subform will of course be a json. But in table 2 the value saved to the field, if done correctly, would be the recid.
In the table list i guess it would be more of a cross table lookup, taking recid, cross referencing the decoded subform, returning the set text field.
SO you want to have a custom field that gets its values from another subform, well we do not need to change JCB to do that, it can already do that.
That is if I understand correctly, you want a custom field that populates from a subfrom in another table. JCB can already do that with custom fields. You will just need to know how to write the PHP and it can work.
Here is how we are doing it in JCB with the conditional fields in the admin view.
Let me know if this is what you are trying to do.
That's not it. Please let me try this again.
In the following screenshot, "Select a Resource/Class" is a custom field, with the following code, which populates perfectly fine:
The stored data in the table for the resource field is 2, which from the dropdown (list) is the value for "Agency".
In the next image, you will see the admin list view, which shows the record I was working on as the first record in the list. JCB is populating the filter dropdown on the left if the values, as you can see. I have checked the code, and the list corresponds to the custom field in the item view:
The issue is that in the "Select a Resource/Class" column of the list view, the column is blank, even though there is a value present in the db field.
I guess i didn't really explain it well. The stored data in that column is a numerical value, which is referencing a name in a subform. The filter is doing it right, or so it seems, but not the column in the view.
Did this make a bit more sense?
Can you give me the code in the model, as this does not look right, there should be a value.
Also the XML of the custom field if you please.
There are actually 2 fields that are doing the exact same thing, but here is the code from the one:
From the model:
This is from the custom field:
Lastly, here is the custom field from the XML in the JCB field (before compile):
Okay now I see... this will not work, as I started to make the tutorial I realized what you really are doing here and that will not work at this time.
Is where is all goes wrong :) or right... depending on who you ask. Since the value saved to the database is
$item['recid']
and the key used to load the value in the list view iskey_field="propclasses"
but the field name isresourcetypes
it can not connect the values accurately. Since you value is hidden in JSON it is sort of impossible for JCB to remap this. Convention is everything, and to build things that works we must try avoid these kind of issues. Mostly because of how c++ works and therefore how mySql works, and therefore how Joomla works and therefore how JCB works.You can still make this work but with some extra custom code in the admin view->Add PHP (getItems Method - before translation fix & decryption).
Then in the helper class you create a public getPropclasslabel method that search for propclass label based on the recid since it is that value that is found in the database.
I must tell you to build JCB to do this via the UI is not going to happen soon, there is just to many pitfalls and edge case that is going to jump up. So it is custom code, but at least inside the JCB custom code area.
Sorry just remove comments that were unrelated 👍
@Llewellynvdm our original idea seems great 🎉
I think the problem with this issue @mwweb is experiencing is due to the compiler removing the subform field from list view. In the Fields class on line 2415
subform
andrepeatable
fields are not being loaded.So @mwweb the short answer is JCB does not allow those field in the list view at this time 😉
But if @Llewellynvdm adds the suggestion made here of allow subfrom fields in the list view, then think can get interesting 😆
Not so sure, the field that is being targeted here is a custom field, so I don't think it is the problem that the field is not being added.
Yes I think we can add the idea to manage the display of the subform and repeatable fields. But what @mwweb is trying to do is some crazy gymnastics that will require some custom code, maybe even direct replacement custom code.
JCB and all its projects are leaving gitHub... this is going to take some time since JCB/VDM is so integrated with github,
The new address is https://gitlab.com/jcb-repos/Joomla-Component-Builder.