User tests: Successful: Unsuccessful:
Resolves issue #14257
Corrects javascript coding errors in #13476
Pull Request for Issue #14257 .
There are logical errors in the javascript in linkedoptions in cms-uncompressed.js that stop the !: showon operator from working in most cases.
for (var i in itemval)
loops over non-enumerable properties and prototypes which means that != will ALWAYS matchitemval = $field.val();
which causes problems.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
Single Select Conditions - choose
The Text or URL fields should appear and switch as you select SubField values
Multiple Select Conditions:
Single Select Conditions
The text and url fields are not affected by the value of Masterfield
Multiple Select Conditions:
Single Select Conditions
p.s. cms-compressed.js will also need changing but I don't know how to generate this.
Status | New | ⇒ | Pending |
Category | ⇒ | JavaScript |
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.
there is no official tool - just use any minifier
Labels |
Added:
?
|
Added updated cms.js (wasn't the same minify tool as was used last time though).
@franz-wohlkoenig would you have time to test this?
@tonypartridge don't understand Instructions like "Create a form with this XML".
@franz-wohlkoenig so it means A basic component which uses JForm use the xml to generate the form.
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.
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.
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
ANDfield2
= 1
ORfield3
= 1
Not sure if we want to go this deep or not, but just another case to take into consideration.
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.
and or is always complex and subject to opinion - i would suggest keeping this simple for now and stick to the original objectives
I have tested this item
Yup, that's perfectly fine :) In which case:
I have tested this item
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.
Status | Pending | ⇒ | Ready to Commit |
RTC after two successful tests.
fyi, while making a pr i found out that showon was not working for filter.xml (searchtools).
for volunteers to look at
I assume you meant here #15621 (comment) or did you find something else
was indeed for modules filters
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:
?
|
@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?
@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
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.
Can you also add the compressed version of the file please.