? ? Pending

User tests: Successful: Unsuccessful:

avatar GeraintEdwards
GeraintEdwards
5 Apr 2017

Resolves issue #14257
Corrects javascript coding errors in #13476

Pull Request for Issue #14257 .

Summary of Changes

There are logical errors in the javascript in linkedoptions in cms-uncompressed.js that stop the !: showon operator from working in most cases.

  1. The primary problem is that for (var i in itemval) loops over non-enumerable properties and prototypes which means that != will ALWAYS match
  2. secondary issue is that multiple select tags get a null from itemval = $field.val(); which causes problems.
  3. radio and checkboxes return a blank value in the current code which always matches a != condition

Testing Instructions

Create a form with this XML

<field name="masterfield" type="radio" default="1" class="btn-group btn-group-yesno" label="MasterField" >
	<option value="0">unknown</option>
	<option value="1">value 1</option>
	<option value="2">value 2</option>
</field>
<field name="subfield" type="radio" default="1" showon="masterfield!:0" class="btn-group btn-group-yesno" label="SubField" >
	<option value="1">Show text field</option>
	<option value="2">Show URL field</option>
</field>
<field name="subText" showon="masterfield!:0[AND]subfield:1" type="text" default="" label="Text - should appear then MasterField is !unknown and subfield is text" />
<field name="subURL" showon="masterfield!:0[AND]subfield:2" size="20" type="url" default="" label="URL - should appear then MasterField is !unknown and subfield is url" />        

<field name="selectlist" type="list" multiple="multiple" default="0" label="Multiple Select Conditions" >
	<option value="0">select a value</option>
	<option value="1">value 1</option>
	<option value="2">value 2</option>
	<option value="3">value 3</option>
	<option value="4">value 4</option>
</field>
<field name="extratext" showon="selectlist!:0" type="text" default="" label="Text should appear when something other than 'select a value' is selected" />

<field name="selectlist2" type="list" default="0" label="Single Select Conditions" >
	<option value="0">select a value</option>
	<option value="1">value 1</option>
	<option value="2">value 2</option>
	<option value="3">value 3</option>
	<option value="4">value 4</option>
</field>
<field name="extratext2" showon="selectlist2!:0" type="text" default="" label="Text should appear when something other than 'select a value' is selected" />

For Masterfield - choose 1 or 2
For SubField choose text or url

Multiple Select Conditions - choose

  1. no values,
  2. 'select a value' and "value 1"
    3, just 'select a value'
  3. just "value 1"

Single Select Conditions - choose

  1. 'select a value'
  2. "value 1"

Expected result

The Text or URL fields should appear and switch as you select SubField values

Multiple Select Conditions:

  1. 'text' field should be visible
  2. 'text' field should be visible
  3. 'text' field should NOT be visible
  4. 'text' field should be visible

Single Select Conditions

  1. 'text' field should NOT be visible
  2. 'text' field should be visible

Actual result

The text and url fields are not affected by the value of Masterfield

Multiple Select Conditions:

  1. 'text' field is visible - correct
  2. 'text' field is visible - correct
  3. 'text' field is visible - INCORRECT
  4. 'text' field is visible - correct

Single Select Conditions

  1. 'text' field is visible - INCORRECT
  2. 'text' field is visible - correct

Documentation Changes Required

p.s. cms-compressed.js will also need changing but I don't know how to generate this.

avatar GeraintEdwards GeraintEdwards - open - 5 Apr 2017
avatar GeraintEdwards GeraintEdwards - change - 5 Apr 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 Apr 2017
Category JavaScript
avatar GeraintEdwards GeraintEdwards - change - 5 Apr 2017
The description was changed
avatar GeraintEdwards GeraintEdwards - edited - 5 Apr 2017
avatar GeraintEdwards GeraintEdwards - change - 5 Apr 2017
The description was changed
avatar GeraintEdwards GeraintEdwards - edited - 5 Apr 2017
avatar brianteeman
brianteeman - comment - 5 Apr 2017

Can you also add the compressed version of the file please.

avatar GeraintEdwards
GeraintEdwards - comment - 5 Apr 2017

Brian - I'm afraid I don't know how that is done. I hunted high and low in Google to no avail. Do you know what the official tool it?

In the meantime the fix can be tested in debug mode.

avatar brianteeman
brianteeman - comment - 5 Apr 2017

there is no official tool - just use any minifier

avatar GeraintEdwards GeraintEdwards - change - 5 Apr 2017
Labels Added: ?
avatar GeraintEdwards
GeraintEdwards - comment - 5 Apr 2017

Added updated cms.js (wasn't the same minify tool as was used last time though).

avatar tonypartridge
tonypartridge - comment - 3 May 2017

@franz-wohlkoenig would you have time to test this?

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 3 May 2017

@tonypartridge don't understand Instructions like "Create a form with this XML".

avatar tonypartridge
tonypartridge - comment - 3 May 2017

@franz-wohlkoenig so it means A basic component which uses JForm use the xml to generate the form.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 3 May 2017

there lacks my Knowledge too. I can test having clear instructions like "click on this and look if that happens, "A basic component which uses JForm use the xml to generate the form" is unclear.

avatar GeraintEdwards
GeraintEdwards - comment - 3 May 2017

You can add the XML to any Joomla component configuration file e.g. add it to the start of the first fieldset of administrator/components/com_contact/config.xml and then open the com_contact options/config page - you'll see the new fields at the top.

avatar C-Lodder
C-Lodder - comment - 22 May 2017

This is working fine based on the test you've given.

As it stands, the OR clause works fine if you're targetting the same field, like so:

<field name="field1" type="radio" default="1" class="btn-group btn-group-yesno" label="field1">
	<option value="0">0</option>
	<option value="1">1</option>
</field>
<field name="field2" type="radio" default="1" class="btn-group btn-group-yesno" label="field2">
	<option value="0">0</option>
	<option value="1">1</option>
	<option value="2">2</option>
</field>
<field name="field3" showon="field1:1[AND]field2:1[OR]field2:2" type="text" default="" label="field3" />

(If field2 is equal to 1 OR 2)

But, let's say I have 4 fields:

<field name="field1" type="radio" default="1" class="btn-group btn-group-yesno" label="field1">
	<option value="0">0</option>
	<option value="1">1</option>
</field>
<field name="field2" type="radio" default="1" class="btn-group btn-group-yesno" label="field2">
	<option value="0">0</option>
	<option value="1">1</option>
	<option value="2">2</option>
</field>
<field name="field3" type="radio" default="1" class="btn-group btn-group-yesno" label="field3">
	<option value="0">0</option>
	<option value="1">1</option>
</field>
<field name="field4" showon="field1:1[AND]field2:1[OR]field3:1" type="text" default="" label="field4" />

Basically, I only want to show field4 if:

  • field1 = 1 AND
  • field2 = 1 OR
  • field3 = 1

Not sure if we want to go this deep or not, but just another case to take into consideration.

avatar GeraintEdwards
GeraintEdwards - comment - 22 May 2017

The problem with [AND] with [OR] is that what is being tested is ambiguous.

Does mean {field1:1[AND]field2:1} [OR]field3:1 or does it mean field1:1[AND] {field2:1[OR]field3:1} or {field1:1[AND]field2:1} [OR]field3:1}

I don't think we would want to handle parenthesis (???) but we could make a documented assumption about the sequence of testing or the priority of operators.

So you decide to work from left to right then field1:1[AND]field2:1[OR]field3:1 would mean {field1:1[AND]field2:1} [OR]field3:1} and if you wanted field1:1[AND] {field2:1[OR]field3:1} you would use field2:1[OR]field3:1[AND]field1:1 in the XML file.

Or you could say that the [AND]s are all tested before the [OR]s (which is less flexible).

My main objective was to resolve the issues with the not (!) operator and handling values from multiple-choice select boxes.

After this PR is accepted then maybe a review of the functionality would be appropriate. For example I've noticed that showons in subforms do not take account of values from the parent form.

avatar brianteeman
brianteeman - comment - 22 May 2017

and or is always complex and subject to opinion - i would suggest keeping this simple for now and stick to the original objectives

avatar C-Lodder
C-Lodder - comment - 22 May 2017

I have tested this item successfully on d2d41ea

Yup, that's perfectly fine :) In which case:


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

avatar C-Lodder C-Lodder - test_item - 22 May 2017 - Tested successfully
avatar tonypartridge
tonypartridge - comment - 22 May 2017

I have tested this item successfully on d2d41ea

Tested with the original scenario given. Works on current suggested usage case, agree if we want more complexity we should open an issue for discussion on the preferred method.


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

avatar tonypartridge tonypartridge - test_item - 22 May 2017 - Tested successfully
avatar franz-wohlkoenig franz-wohlkoenig - change - 22 May 2017
Status Pending Ready to Commit
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 22 May 2017

RTC after two successful tests.

avatar infograf768
infograf768 - comment - 22 May 2017

fyi, while making a pr i found out that showon was not working for filter.xml (searchtools).
for volunteers to look at ?

avatar brianteeman
brianteeman - comment - 22 May 2017

I assume you meant here #15621 (comment) or did you find something else

avatar infograf768
infograf768 - comment - 22 May 2017

was indeed for modules filters

avatar rdeutz rdeutz - change - 22 May 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-05-22 19:08:23
Closed_By rdeutz
Labels Added: ?
avatar rdeutz rdeutz - close - 22 May 2017
avatar rdeutz rdeutz - merge - 22 May 2017
avatar GeraintEdwards
GeraintEdwards - comment - 23 May 2017

@infograf768 I'm happy to take a look at the showon/filter.xml issue but the issue referenced by Brian is closed. Can you elaborate on the issue you have found?

avatar brianteeman
brianteeman - comment - 23 May 2017

@GeraintEdwards it is closed because JM wrote a different solution to work around that bug.

If you look at 3.7.0 you can see https://github.com/joomla/joomla-cms/blob/3.7.0/administrator/components/com_modules/models/forms/filter_modules.xml#L55

and to put it simply that line did nothing

avatar GeraintEdwards
GeraintEdwards - comment - 23 May 2017

Got you - thanks. I just checked JM's changes and this showon fix would also have resolved the issue for the page filter display though it may not have helped any search values in the session/registry when switching from site to admin.

avatar infograf768
infograf768 - comment - 23 May 2017

What I did was to unset here
#16118

Add a Comment

Login with GitHub to post a comment