Skip to content

053 Quick Subform Demonstration

Amigo edited this page Sep 5, 2019 · 13 revisions

QUICK SUBFORM DEMONSTRATION

Request On The Forum

00:00:00 (Click on these time links to see Youtube video)

I recently had this request on the Forum by Marco, regarding some help with subforms.

"How to generate a subform itself from within JCB. Where to find the XML detail in relation to repeated subform fields in view. How the data of the subform is populated. How posted data of a subform is validated. 00:00:32 How data of a subform is processed and persisted. My assumption is that the above is done as part of JCB and would not require manual construction of xml files. I did googled but found an answer to no avail."

At the moment we have only made tutorials about Repeatable Fields. 00:01:01 Repeatable Fields as such has been discontinued. A tutorial about subforms has not been made yet.

Subforms - Create Fields You Want To Use

00:01:13

Subforms have fields in them. For example, go to component and open this(Demo) Admin view. This is a subform(Follow on video). Each of these little fields is a field in the subform. It is only an ID which you need to add to create the subform. 00:01:44 First create a Custom field that grabs values out of the Admin view. This(Icon) is a list field, to create a list field and this is a checkbox, etc. First, create these fields.

First Create A New Field

00:02:06

That is the first thing to do, create a field you want to use in the subform. For instance, I am going to use existing fields just as a demonstration. There are Description, Mobile, Name, etc. 00:02:27 First we want to create a new field. First, open it that we have both open to get the IDs. Then click New, then select Subform, and it populates the XML.

Look At The Tutorials - YouTube - Joomla Component Builder

00:02:51

If you have not looked at all the tutorials that are available on YouTube, then a lot of this will not make sense. For those that may be just seeing this video and not watched any of the other tutorials, please go to YouTube and type in Joomla Component Builder and try to find the playlist. Start at the top working through way down. I know those tutorials will make you quite able to build amazing things.

Formsource

00:03:51

This formsource(Optional) - it reads as follows: 'You can add a path to an XML file containing the fields'. So a custom XML file can be added to your component. How to add custom files to component, is a whole another topic. It is also possible within the Joomla Component to add files and folders, etc. That means this specific source can still be used but you do not need to. If you use the fields option then you need to remove the source option. 00:04:23 Either the one or the other of these options should be used. Currently, the fields are set to mandatory. By going to the field types it can be changed to be optional and then you can select other fields or formsource. The compiler will, in any case, detects a formsource will behave correctly.<<<<<<<<<<

Adding IDs

00:04:57

We need to add the IDs so we can come here(Fields) and I want to have Name, it's just 199. 00:05:04 I add 199 and a comma and then let's add something else. Let's add Website 280. Let's do an Email as well and it's 100. We have that in place.

Adding A Description, Maximum, Filter, Showon

00:05:33

We can add a description. We can add a maximum, a filter, a showon. I'm just going to leave this. The validation of these fields, I think that is an area that I haven't looked into. But if I'm correct and also the reason why they moved away from Repeatable Fields, is that every field is validated on its own merit. For example, 00:06:05 the Name field, if you create a Name field, you're saying I want this to be a string and it has this filter string value. Since this is part of the XML it will be validated on this. I can be mistaken. I haven't looked at the code. That's what I anticipate it will do. In most cases I would say anticipate that it doesn't and try and do some custom scripting. I'm not going to illustrate that now. 00:06:44 You need to know a little bit more about JCB which there are tons of the tutorials to show you how to do custom scripting all around it a component and even to do custom scripting anywhere and any area of the component through the custom code area implementation. I'm going to talk more about that. Make sure it got all the spelling right. 00:07:15 I'm going to save this, just give it a Name: Options (test), so I can see it. This Data Type I would make TEXT. The default means that JCB (the Store method) already will detect that this is a Subform and will add the needed 00:07:39 PHP in storing the file and in loading the file into the form again. So that takes care of that. So you don't need to say Json, it will on its own by its default do the correct implementation. In the Data Type so you need to make sure either to click TEXT or MEDIUMTEXT depending on what this value is going to be. Anyway, I think for 50 text is quite enough. Save and close.

Adding Options(test) Subforms To Any Admin View - See Video

00:08:19

Let's see we got that field. I'm going to add it to any admin view for now. I'm going to add it to Look View, that we can see it in action. The look view is part of the Demo component. I'm just going to dump it here. Let's see the above tab, full width, details, description. I think let's just add it there. Details also full width, make it the 2nd, and I say 00:08:49 Options(test). Save and close. We've added it to a view. Now I'm just going to compile this component which the view belongs to. Which at this stage it is demo and install it. Now let's go open that Demo component, and open Looks. And here we go, enter name here, enter website address, enter email. We click the green plus button 00:09:26 and our values are there. Let's just save one. Children. We can do I think that's the only one. (see video)Let's do that and by entering those values I'm just going to grab joomlamount.com up here, 00:09:55 paste it in there a few times. I'm going to put [email protected] in Email. To get sort of a feel for it. Save. It saved the values, it loaded it back, it's done all of that. 'Hi, there' then save and close. 00:10:45 If we open it again, it shows it up again. We can shuffle it, put number four on top. Save and close. Open again and so it is loading it also correctly. That's a quick demonstration Marco I hope this helps 00:11:09 and getting you able to use subforms with JCB. It's as easy as that.

Clone this wiki locally