J3 Issue ?
avatar hennysmafter
hennysmafter
7 Feb 2017

Steps to reproduce the issue

Create into the basic fieldset:

<field
  name="switch"
  type="list"
  label="Switch"
  description="Switch between transportation"
  default="notheme">
  <option value="car">car</option>       
  <option value="bike">bike</option>
  <option value="plane">plane</option>
</field>

Create a new tab and insert a subform, Then inside the subform add this:

<field 
  type="spacer" 
  name="carheader" 
  class="text" 
  showon="switch:car"
  label="CAR HEADER"
/>
<field 
  type="spacer" 
  name="bikeheader" 
  class="text" 
  showon="switch:bike"
  label="BIKE HEADER"
/>
<field 
  type="spacer" 
  name="planeheader" 
  class="text" 
  showon="switch:plane"
  label="PLANE HEADER"
/>

Expected result

When switching between the select options on the basic tab it should show only the corresponding item on the tab with the SubForm.

Actual result

No matter what is selected it always show all of the fields on the SubForm

System information (as much as possible)

Latest Joomla 3.6.5
Latest PHP 7 & 5 series

Additional comments

I have seen some related issues but they are only vagily related.

https://issues.joomla.org/tracker/joomla-cms/11548
But this deals with showon function within the SubForm I am talking about the showon from another tab.

https://issues.joomla.org/tracker/joomla-cms/12511
This one is I believe the answer to the previous one and again is only about the showon from within the SubForm

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar hennysmafter hennysmafter - open - 7 Feb 2017
avatar joomla-cms-bot joomla-cms-bot - change - 7 Feb 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 7 Feb 2017
avatar Fedik
Fedik - comment - 7 Feb 2017

Sorry for disappointing, your expectation is wrong.
Subform it is separated form with an own scope.

The described behavior is correct.

For your example.
Try to add the field with name="switch" in to your subform xml, and tell, me which showon behavior should be now? ?

avatar hennysmafter
hennysmafter - comment - 7 Feb 2017

@Fedik I am not quite sure why the expectation is wrong.

The showon function is a Joomla function that existed before the Subform existed. So it can be understood that when a new function is added it works with the older ones. And Showing/Hiding from other tabs have worked for so many years now that I have a hard time believing it was specifically coded to ignore the Show/Hide. And if it is not specifically coded to ignore then it is either a bug or a oversight.

But as I understand it right it requires me to write my own show/hide function in this case.

avatar mbabker
mbabker - comment - 7 Feb 2017

I'm not familar with showon, but from reading this thread, it seems the architecture is that subforms are actually another complete form instance and you're asking for the showon feature to be able to support altering the display state based on a field in another form.

Personally, I think that might be a little outside scope for what Joomla should do out of the box.

avatar hennysmafter
hennysmafter - comment - 7 Feb 2017

@mbabker I understand the logic from @Fedik and I understand what you are saying but I am sure that there are more people out there who share my opinion.

Because when we develop a extension we use the Joomla Documentations. Then in there you find the SubForm and you find the ShowOn function. We can combine the ShowOn with every field type so therefore we just naturally assumed it would also work with SubForms.

Now it is clear to me that it does not so I have to code it myself. No problem but a heads up on the Documentation would have been nice.

avatar hennysmafter
hennysmafter - comment - 7 Feb 2017

@Fedik Still loving the SubForm though and Joomla off course. And if I find a good way to make it work I will share the code in this issue. Then someone else can take it up to do pulls/merges etc.

avatar Fedik
Fedik - comment - 8 Feb 2017

@hennysmafter but you did not answered ?

what showon should do when both forms (the main and subform) will have the field with the name name="switch"?
see the problem now? ?

avatar hennysmafter
hennysmafter - comment - 8 Feb 2017

@Fedik I don't understand what you mean. I have read it 3 times but I am really confused. Can you tell me what will happen then? Thanks.

The reason I am so confused is that I would never add twice a field with the name="switch" because that would be just stupid. So I don't really see why you want me to try it. Or is to make the point that the SubForm is a seperate form and therefore it does allow to use the switch name twice. One outside the SubForm and one inside.

And yeah I could just test it but this is more fun :-)

avatar Fedik
Fedik - comment - 8 Feb 2017

your main form:

<field
  name="switch" 
  type="list" label="Switch"   default="notheme">
  <option value="car">car</option>       
  ....
</field>

your subform:

<field  type="spacer" name="carheader" 
  showon="switch:car"
  label="CAR HEADER" />

<field  type="spacer"  name="bikeheader" 
  showon="switch:bike"
  label="BIKE HEADER" />

<field type="spacer"  name="planeheader" 
  showon="switch:plane"
  label="PLANE HEADER"/>

<field
  name="switch" 
  type="text" label="Switch"  />

Now the switch field twice, inside subform and inside the main form.
How showon should work now? ?

avatar hennysmafter
hennysmafter - comment - 8 Feb 2017

Ahhh. Now I understand what you mean.

In this case I still would say not to use the same name multiple times but in case it is like your example then I would say that the Main Form should be the boss. So the ShowOn from the main form should be the only one that makes the other items shown/hidden.

So basically the ShowOn Function should change. We already have [AND] & [OR] capabilities but maybe we can also do [FORM:SubFormName]switch:car. This might mean that the place of the subforms can only be in one spot. If you ask me what that spot should be I would say: mod_somename/models/forms
So if in this folder there was a subform called: aBc then the code would become [FORM:aBc]switch:car

Wouldn't you agree that it would be nice to have the showon function work over the main and subforms. I hope it is a good idea. Unfortunately I don't know how to implement that otherwise I would have already done it.

So at this point I created a code that first of all added the class from the label to the control-group and from that I used the below code:

    $('#selectboxid').bind('change', function (e) {
      if( $('#selectboxid').val() == '0') {
        $( ".subform-repeatable-group div[class*='somepartoftheclassname']" ).hide();
      } else if( $('#selectboxid').val() == '1') {
        $( ".subform-repeatable-group div[class*='somepartoftheclassname']" ).show();
      }
    }).trigger('change');

Now when you have multiple showons inside the subform then you need to reset those to their default values when switching the selectboxid for that I just used:

$("select[id$='endingoftheclass']").val("select");

avatar Bakual
Bakual - comment - 8 Feb 2017

I think what you're requesting is a quite specific feature which can as well be done with some custom JavaScript.
I fear if we implement this into core, it could become very complex when at the same time the custom code needed would be quite simple.

avatar hennysmafter
hennysmafter - comment - 8 Feb 2017

I think what you're requesting is a quite specific feature which can as well be done with some custom JavaScript.

I don't think it is quite specific to have showing/hiding of element if it was so specific the entire ShowOn function would not exist.

I fear if we implement this into core, it could become very complex when at the same time the custom code needed would be quite simple.

When this is implemented into the core then it becomes for the core developers hard work but for the end developers developing a extension it becomes real easy.

For instance this is now when you have it all into 1 form

<field name="mylistvalue" type="list" default="" required="true" label="Select an option" description="">
  <option value="select">Please Select</option>
  <option value="0">Option 1</option>
  <option value="1">Option 2</option>
</field>

<field 
  name="mytextvalue" 
  type="text" 
  default="Some text" 
  label="Enter some text" 
  description="" 
  showon="mylistvalue:1"
  size="10" 
/>

But when you have it in multiple forms you get this.

Form 1 (mainform)

<field name="mylistvalue" type="list" default="" required="true" label="Select an option" description="">
  <option value="select">Please Select</option>
  <option value="0">Option 1</option>
  <option value="1">Option 2</option>
</field>

Form 2 (subform)

<field 
  name="mytextvalue" 
  type="text" 
  default="Some text" 
  label="Enter some text" 
  description="" 
  showon="[FORM:root]mylistvalue:1"
  size="10" 
/>

So I disagree completely that [FORM:root] makes things more complicated then:

    $('#selectboxid').bind('change', function (e) {
      if( $('#selectboxid').val() == '0') {
        $( ".subform-repeatable-group div[class*='somepartoftheclass']" ).hide();
      } else if( $('#selectboxid').val() == '1') {
        $( ".subform-repeatable-group div[class*='somepartoftheclass']" ).show();
      }
    }).trigger('change');

Especially for the people that just started creating extensions for the Joomla CMS system.

avatar Bakual
Bakual - comment - 8 Feb 2017

I don't think it is quite specific to have showing/hiding of element if it was so specific the entire ShowOn function would not exist.

Of course I referred to your specific proposal here to have showon working across forms. Not to the whole showon feature.

When this is implemented into the core then it becomes for the core developers hard work but for the end developers developing a extension it becomes real easy.

There are no core developers.
Please keep in mind that more complex code also means more possibilities for bugs and less maintainability. Imho we should find a balance between maintainable code and supporting every edge case.

So I disagree completely that [FORM:root] makes things more complicated

Of course I didn't talk about the needed declaration in the XML but about the code needed which parses that declaration and the JS which has to track the states across multiple forms and taking care of possible duplicates.
You also suggested to limit where the subform can be located which imho isn't acceptable anyway.

OHHH Wait. This code above can't just be put into the XML. No no first you need to create a custom field like:

The custom code can be loaded in the view/layout just fine and in the XML you only reference the JS function call in the onchange attribute. You shouldn't need a custom formfield for that in your extension. And even if you would need one for whatever reason, it's actually very simple to create one.

Then you must be the king of coding

No need to get impolite.

avatar franz-wohlkoenig franz-wohlkoenig - change - 30 Mar 2017
Category UI/UX
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Apr 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-04-05 11:23:40
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - close - 5 Apr 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 5 Apr 2017

closed as Discussion ended. @hennysmafter feel free to reopen for further Discussion.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13967.

avatar joomla-cms-bot
joomla-cms-bot - comment - 5 Apr 2017
avatar uglyeoin
uglyeoin - comment - 26 May 2018

Just to add that I ran across exactly the same problem and expected exactly the same result. I understand the difficulties after reading this discussion. My solution was to create multiple subforms and then use showon on the subform field. Thus showons were only in the main XML file and I could still have repeatable fields the way I wanted them.

avatar uglyeoin
uglyeoin - comment - 16 Aug 2019

I just came back here searching for an answer from Google. I'd like to firstly thank myself for providing the answer, and secondly I'd like to post my answer in more detail. I put it on Stack Overflow for neatness.

https://joomla.stackexchange.com/questions/25047/how-to-use-subform-in-nested-subforms/25048

avatar franz-wohlkoenig franz-wohlkoenig - change - 17 Aug 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 17 Aug 2019

Add a Comment

Login with GitHub to post a comment